I have a pre-built resource adapter archive (*.rar
) file which I need to make part of a Netbeans Enterprise Application project.
In project properties in Build > Packaging
I added this *.rar
file and set Location In Archive
to root (/
).
There's also an EJB module project that uses classes from the *.rar
. When I build the *.ear
file and deploy it manually to Glassfish, all is fine, I don't even have to write application.xml
.
However, when I deploy the app project from Netbeans, my EJB can't access the classes within the *.rar
and throws a NoClassDefFoundError
. If I put the file application.xml
into src/conf/
, deploy from Netbeans fails with:
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>
How to make Netbeans unpack the rar while deploying?
How do you normally develop resource adapters (not pre-built, native projects, not Maven) with Netbeans? I don't see a template for that.
My Netbeans is 8.2 shipped with Glassfish 4.1.1.
I found that the Netbeans build script uses the <nbdeploy>
task to cleanup, prepare, and deploy the dist/gfdeploy/Appname
directory. This task copies everything from ${build.dir}
, so it should be possible to unpack the rars in the pre-run-deploy
hook.
After copying, <nbdeploy>
unpacks the jar files, but not the rar files. The jars are unpacked into subdirs with the same name, only the .jar
suffix is replaced with _jar
.
The <nbdeploy>
task is called by the -run-deploy-nb
target and only when run from Netbeans (when ${netbeans.home}
is set).
Knowing that, I added the pre-run-deploy
hook in my build.xml
:
<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>
Actually, my target is much more complex, because I wanted to expand each file in ${build.dir}
matching the *.rar
pattern. The full build.xml
is here: https://gist.github.com/basinilya/c2c1ad3fc0df2323fc5c5337c19648bb