我有一个预构建的资源适配器归档(*.rar
(文件,需要将其作为Netbeans Enterprise Application项目的一部分。
在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
钩子中解压缩rar。
复制后,<nbdeploy>
将打开jar文件,但不打开rar文件。jar被解压缩到具有相同名称的子目录中,只有.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="1_2" />
</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