views:

45

answers:

2

I'm using solaris, I created a maven app on jdk 1.6 but using the maven-compiler-plugin to specify the target as 1.5. Here is the snippet of my pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.5</source>
      <target>1.5</target>
    </configuration>
  </plugin>

Although when I try to run in the solaris box I get:

bash-2.05$ ./merchantInfoUpdate.sh 
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

And if I run the mvn install -X (with debug) and the compiler plugin tells me:

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile' -->
[DEBUG]   (f) basedir = /home/emerson/newworkspace/java-batch-updater
[DEBUG]   (f) buildDirectory = /home/emerson/newworkspace/java-batch-updater/target
[DEBUG]   (f) classpathElements = [/home/emerson/newworkspace/java-batch-updater/target/classes, /home/emerson/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar, /home/emerson/.m2/repository/log4j/log4j/1.2.12/log4j-1.2.12.jar]
[DEBUG]   (f) compileSourceRoots = [/home/emerson/newworkspace/java-batch-updater/src/main/java]
[DEBUG]   (f) compilerId = javac
[DEBUG]   (f) debug = true
[DEBUG]   (f) failOnError = true
[DEBUG]   (f) fork = false
[DEBUG]   (f) optimize = false
[DEBUG]   (f) outputDirectory = /home/emerson/newworkspace/java-batch-updater/target/classes
[DEBUG]   (f) outputFileName = com.company.ingestion.updater-2010.01
[DEBUG]   (f) projectArtifact = com.yell:com.company.ingestion.updater:jar:2010.01
[DEBUG]   (f) showDeprecation = false
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) source = 1.5
[DEBUG]   (f) staleMillis = 0
[DEBUG]   (f) target = 1.5
[DEBUG]   (f) verbose = false

emerson@emerson-desktop:~/newworkspace/java-batch-updater/target/expand$ file com/yell/ingestion/updater/ListingsManager.class

com/yell/ingestion/updater/ListingsManager.class: compiled Java class data, version 50.0 (Java 1.6)

Java version:

bash-2.05$ java -version
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Server VM (build 1.5.0_05-b05, mixed mode)

Start script content:

bash-2.05$ more merchantInfoUpdate.sh 
LIB=lib

   CLASSPATH="."
   for i in `find $LIB  -name *.jar`; do CLASSPATH="$CLASSPATH:$i"; done;
    export CLASSPATH
   CLASSPATH=$CLASSPATH:resources/properties
java  $* -cp $CLASSPATH com.company.ingestion.updater.ListingsManager 

I made sure it is actually the jar I'm building which is causing the problem, leaving it alone in the app classpath, and still I get the same error.

Any ideas?

Thanks

+1  A: 

Are you absolutely certain you're using Java 1.5 on the Solaris box, not 1.4? What's the output of java -version there? What does merchantInfoUpdate.sh contain? Does it put any other library JARs into the classpath, which may be compiled using the Java 1.6 class file format?

Michael Borgwardt
Hi Michaelyes, I'm sure we are using 1.5, I added the java -version output on the question.I added the content of my start script.Yes there is other jars in the classpath, but I removed them when running in the server and still get the "Bad version number" error. And any way, the compiled class itself shows as being compiled with 1.6 (see the "file" command result).Thanks for helping
Emerson
@Emerson: It looks like Maven is taking the compiler configuration from somewhere else then, because even if the snippet you posted would be ignored for some reason, the default target version is 1.5 according to http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.htmlhttp://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
Michael Borgwardt
Hi Michael, it wasn't being ignored, if I would change the target at the pom to 1.6 the file command would show that. The problem is that I wasn't running the clean goal before.Thanks for the help!
Emerson
A: 

Seems that somehow maven concludes that the classes don't need to be compiled· I re-run the install with a clean, and this time I could see the right version:

mvn clean install

and then..

file /home/emerson/newworkspace/java-batch-updater/target/classes/com/company/ingestion/updater/ListingsManager.class /home/emerson/newworkspace/java-batch-updater/target/classes/com/company/ingestion/updater/ListingsManager.class: compiled Java class data, version 49.0 (Java 1.5)

Thanks all for the help!

emerson

Emerson