将预构建的资源适配器归档部署为企业应用程序项目的一部分

Deploy pre-built resource adapter archive as part of Enterprise Application project

我有一个预构建的资源适配器存档 (*.rar) 文件,我需要将其作为 Netbeans 企业应用程序项目的一部分。

Build > Packaging 的项目属性中,我添加了这个 *.rar 文件并将 Location In Archive 设置为根 (/)。

还有一个 EJB 模块项目使用 *.rar 中的 类。当我构建 *.ear 文件并将其手动部署到 Glassfish 时,一切都很好,我什至不必编写 application.xml.

但是,当我从 Netbeans 部署应用程序项目时,我的 EJB 无法访问 *.rar 中的 类 并抛出 NoClassDefFoundError。如果我将文件 application.xml 放入 src/conf/,从 Netbeans 部署失败:

IllegalArgumentException: Expected to find an expanded directory for submodule my.rar but found a JAR.  If this is a directory deployment be sure to expand all submodules.

application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC
    "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"
    "http://java.sun.com/dtd/application_1_3.dtd">
<application>
  <display-name>EnterpriseApplication1</display-name>
  <module>
    <connector>my.rar</connector>
  </module>
  ...
</application>

如何让 Netbeans 在部署时解压 rar?

您通常如何使用 Netbeans 开发资源适配器(不是预构建的本地项目,不是 Maven)?我没有看到相应的模板。

我的 Netbeans 是 8.2,附带 Glassfish 4.1.1。

我发现 Netbeans 构建脚本使用 <nbdeploy> 任务来清理、准备和部署 dist/gfdeploy/Appname 目录。此任务从 ${build.dir} 复制所有内容,因此应该可以在 pre-run-deploy 挂钩中解压 rars。

复制后,<nbdeploy> 解压 jar 文件,但不解压 rar 文件。罐子被解压到同名的子目录中,只有 .jar 后缀被替换为 _jar.

<nbdeploy> 任务由 -run-deploy-nb 目标调用,并且仅当 运行 来自 Netbeans 时(当设置 ${netbeans.home} 时)。

知道后,我在 build.xml 中添加了 pre-run-deploy 挂钩:

<target name="pre-run-deploy" if="netbeans.home">
    <fileset dir="${build.dir}" id="nth.archive">
        <include name="my.rar">
    </fileset>
    <pathconvert property="extract.dir" refid="nth.archive">
        <!-- replace last dot with underscore -->
        <mapper type="regexp" from="(.*)[.](.*)" to="_" />
    </pathconvert>
    <delete dir="${extract.dir}"/>
    <unzip dest="${extract.dir}">
        <resources refid="nth.archive"/>
    </unzip>
    <delete>
        <fileset refid="nth.archive"/>
    </delete>
</target>

实际上,我的目标要复杂得多,因为我想扩展 ${build.dir} 中的每个文件以匹配 *.rar 模式。完整的 build.xml 在这里:https://gist.github.com/basinilya/c2c1ad3fc0df2323fc5c5337c19648bb