I'm using an ant build.xml that generates classes and compiles them with the
tools.jar from the JDK.

I am using MAVEN 2.2.1 version. JDK 1.5 to execute MAVEN. As maven 2.2.1
version supports higher then JDK 1.5 only so I have to use it.

This maven-antrun-plugin doesn't allow to specify neither source or target
version for the compiler.
So, the generated classes are compiled against the currently running JVM
which is JDK , using its rt.jar and the tools.jar provided in plugin
dependencies (or placed in the lib/ext directory of the jvm).

As Maven is executed in a 1.5 JVM (jdk1.5.0_22) is needed for my project to
compile these classes with JDK 1.4.2 version because the server where I want
to deploy them is running on a 1.4 JVM, so I am getting exception while I am
compiling with MAVEN plugin from my eclipse or command line.

I couldn't find a way to tell antrun to compile my classes using a different
java version.
I tried the following workarounds :

change the tools.jar dependency to point to a 1.4 version => as the compiler
uses the rt.jar from the currently running 1.5 JVM, the class file version
doesn't match (version 49.0, expecting 48.0)

add a dependency to a 1.4 rt.jar => it doesn't change anything, as the
rt.jar should be specified in the boot classpath.


Following one is the sample code which i am using.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>install</id>
            <phase>install</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
                <compilerVersion>${java-version}</compilerVersion>
                <compilerArguments>
                    <classpath>${java.home}/lib/tools.jar</classpath>
                    <classpath>${java.home}/jre/lib/rt.jar</classpath>
                </compilerArguments>
                <tasks>
                    <ant antfile="WPSEjb_build.xml"/>
                </tasks>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>crimson</groupId>
            <artifactId>crimson</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>sun.jdk</groupId>
            <artifactId>tools</artifactId>
            <version>1.4.2</version>
            <scope>system</scope>
            <systemPath>${java.home}/lib/tools.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>rt</artifactId>
            <version>${java-version}</version>
            <scope>system</scope>
            <systemPath>${java.home}/jre/lib/rt.jar</systemPath>
        </dependency>
    </dependencies>
</plugin>


I am getting exceptions something like this.

WPSClient.java:22: cannot access java.lang.Object
 [wlwBuild] [Build] bad class file:
C:\Java\jdk1.5.0_22\jre\lib\rt.jar(java/lang/Object.class)
 [wlwBuild] [Build] class file has wrong version 49.0, should be 48.0
 [wlwBuild] [Build] Please remove or make sure it appears in the correct
subdirectory of the classpath.
 [wlwBuild] [Build] public static WPSServerRemote getWPSServer() throws
MitchellException {
 [wlwBuild] [Build] ^
 [wlwBuild] [Build] 3 errors
 [wlwBuild] [Build] BUILD FAILED
 [wlwBuild] [Build] Compile failed; see the compiler error output for
details.
 [wlwBuild] [Build]
 [wlwBuild] java.lang.reflect.InvocationTargetException
 [wlwBuild] java.lang.reflect.InvocationTargetException
 [wlwBuild]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
 [wlwBuild]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [wlwBuild]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [wlwBuild]     at java.lang.reflect.Method.invoke(Method.java:592)
 [wlwBuild]     at workshop.core.Compile.start(Compile.java:19)
 [wlwBuild]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
 [wlwBuild]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [wlwBuild]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [wlwBuild]     at java.lang.reflect.Method.invoke(Method.java:592)
 [wlwBuild]     at workshop.core.Starter.invokeStart(Starter.java:34)
 [wlwBuild]     at workshop.core.Compile.main(Compile.java:9)
 [wlwBuild] Caused by: java.lang.NoClassDefFoundError:
org/apache/crimson/tree/XmlDocument
 [wlwBuild]     at
workshop.util.ide.PreferencesNode._export(PreferencesNode.java:540)
 [wlwBuild]     at
workshop.util.ide.PreferencesNode.exportSubtree(PreferencesNode.java:820)
 [wlwBuild]     at
workshop.util.ide.PreferencesNode.flush(PreferencesNode.java:984)
 [wlwBuild]     at workshop.core.App$15.run(App.java:1000)
 [wlwBuild]     at
workshop.core.asynctask.AsyncTaskManager.showDialogWhileRunning(AsyncTaskManager.java:272)
 [wlwBuild]     at
workshop.core.asynctask.AsyncTaskManager.showDialogWhileRunning(AsyncTaskManager.java:482)
 [wlwBuild]     at workshop.core.App.exit(App.java:994)
 [wlwBuild]     at
workshop.core.CompileHelper.compile(CompileHelper.java:298)



Please let me know HOW CAN I SETUP JDK 1.4.2 Version to Compile my classes
by using maven-antrun-plugin.

Reply via email to