ObjectDB ObjectDB

Compile time enhancement using build.xml of a Netbeans web application

#1

Does anybody have a complete, working example of the adaptations required in the build.xml of a Netbeans web application project to specify ObjectDB compile time enhancement, for both single file and whole project compilation ?

The ObjectDB 2.3 manual gives the following tip:

<java classname="com.objectdb.Enhancer" fork="true"
classpath="c:\objectdb\bin\objectdb.jar">
<arg line="-s c:\my-project\classes\*.class"/>
</java>

The (rather overwhelming) nbproject/build-impl.xml of Netbeans, that is included into build.xml, offers a number of empty targets to override in build.xml, such as -post-compile and -post-compile-single. I do not see yet how to relate the manual's example above to these targets and to the various variables available to the Netbeans build.xml via build-impl.xml.

I have thankfully not had to work with ANT in depth or adapt a build.xml for some years, and am not an expert with ANT. A complete example for Netbeans uploaded here would be very helpful.

Until now I have been working with run-time enhancement using objectdb.jar as a javaagent, but I am now seem to be getting clashes between ObjectDB enhancement and JRebel, as reported under: JRebel integration feature, so I want to try compile time enhancement. Besides, as the ObjectDB manual says:

Enhancement by a Java agent is very easy to use and convenient during development. For release, however,
it is recommended to integrate the enhancement in the build process.

Grateful for examples,

Webel

edit
delete
#2

Update. The following in a Netbeans web application build.xml works for an entire build:

<target name="-post-compile">
  <echo message="begin ObjectDB enhancer"/>
   <java classname="com.objectdb.Enhancer" fork="true" classpath="/usr/local/objectdb/objectdb/bin/objectdb.jar:${javac.classpath}:${j2ee.platform.classpath}">
   <arg line="-s ./build/web/WEB-INF/classes/*.class"/>
  </java>
<echo message="end ObjectDB enhancer"/>
</target>

(Where obviously the path to your objectdb.jar has to be adapted.)

However, I want to have a version of this that works with -post-compile-single acting on single files (incremental compilation) and works with Netbeans Compile on Save (CoS). I have requested help on the Netbeans forum.

edit
delete
#3

I wrote: 

I want to have a version of this that works with -post-compile-single acting on single files (incremental compilation) and works with Netbeans Compile on Save (CoS)

Update: I haven't managed to figure out how to apply the ObjectDB enhancer with NetBeans Compile-on-Save option on, because as far as I can tell when using Compile-on-Save NetBeans uses cached files and does not execute the -post-compile-single Ant task in the usual Java web app build.xml.

However, I have figured out how to get ObjectDB to work when Compile-on-Save is off, this may be of use to someone else (you will have to adapt the objectdbjar path property):

<property name="objectdbjar" value="/usr/local/objectdb/objectdb/bin/objectdb.jar"/>
<target name="-post-compile-single">
<!--
Adapted from http://stackoverflow.com/questions/1176071/replacing-characters-in-ant-property
Use string replacement to capture the compiled class file from the input java file.
-->
 <loadresource property="compiled">
  <propertyresource name="javac.includes"/>
  <filterchain>
   <tokenfilter>
    <filetokenizer/>
    <replacestring from=".java" to=".class"/>
   </tokenfilter>
  </filterchain>
 </loadresource>
 <echo message="post compile single: begin ObjectDB enhancer"/>        
 <java classname="com.objectdb.Enhancer" fork="true" classpath="${objectdbjar}:${javac.classpath}:${j2ee.platform.classpath}">
   <arg line="-s ./${build.classes.dir}/${compiled}"/>
 </java>
 <echo message="post compile single: end ObjectDB enhancer"/>
</target>
edit
delete
#4

Thank you for this update.

ObjectDB Support
edit
delete
#5

NetBeans Compile-on-Save seems to use the internal compiler to write .sig files, rather than .class files, to the NetBeans cache, and side-steps any build.xml commands. I can easily apply the ObjectDB enhancer on a per-file basis; I just have to explicitly run/hit Compile for any changed file to trigger my custom per-file enhancement task in the build.xml.

edit
delete

Reply

To post on this website please sign in.