0
votes

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

2
Thanks seanizer, I will make sure I will accept the best answers.Emerson
Please provide the value of your $PATH envar.Janek Bogucki
Hi Janet, here it is: PATH=.:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/openwin/bin:/usr/lbin::/oracle/app/oracle/product/9.2.0/bin:/bin:/usr/bin:/usr/ccs/bin:/home/user/ant/apache-ant-1.6.2/binEmerson
What do to get from "javac -version" (instead of java -version)?Janek Bogucki

2 Answers

1
votes

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?

0
votes

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