0

I trying to run Maven 3.0.4 with java 6. Below is my bash profile and attached screenshots to validate location:

JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export JAVA_HOME


M2_HOME=/Users/bchart545/apache-maven-3.0.4
export M2_HOME

PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

export PATH

enter image description here enter image description here I've tried both: Unsupported major.minor version 51.0 and mvn -v gives me "Unsupported major.minor version 51.0"

Not seeing what I'm missing, I want it to run with Java 6. Thanks and sorry for the new post.

Billy
  • 1,049
  • 3
  • 14
  • 23
  • Show us the full stacktrace. – Andreas Mar 30 '20 at 21:22
  • Are you sure you have `[![JAVA_HOME=...` and not `JAVA_HOME=...`? Run the command `set -x` and then in the same command line window `mvn -v` and post the output. – Karol Dowbecki Mar 30 '20 at 21:24
  • COSML-1718672:~ bchart545$ mvn -v Exception in thread "main" java.lang.UnsupportedClassVersionError: org/codehaus/plexus/classworlds/launcher/Launcher : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) – Billy Mar 30 '20 at 21:24
  • Hi @KarolDowbecki, my bash profile is exactly as above in comment, it was a typo in my post. Still getting error. Thank you for clarifying. – Billy Mar 30 '20 at 21:28
  • Use `set -x` to see what exactly `mvn` is executing, it's just another script. It could be that you have another `JAVA_HOME` definition but you won't know until you debug `mvn` script. – Karol Dowbecki Mar 30 '20 at 21:30
  • I'm sorry @KarolDowbecki, what is `set -x` and where do I use it? – Billy Mar 30 '20 at 21:34
  • Remove the `M2_HOME` and only add the path to the `bin` directory of Maven to your path...Apart from that please use more recent version of Maven (or at least Maven 3.0.5) ...why do you need Java 6 ? – khmarbaise Mar 30 '20 at 23:26
  • @khmarbaise Ok, i'll try that. We need Java 6 cause this app is a VERY legacy app. Looking to get it run locally. – Billy Mar 30 '20 at 23:28
  • 1
    You can use most recent Maven version and use toolchain to compile/run tests with older JDK version... – khmarbaise Mar 30 '20 at 23:28
  • @khmarbaise Commented out the `#M2_HOME=/Users/bchart545/apache-maven-3.0.5` and set `PATH=$PATH:/Users/bchart545/apache-maven-3.0.5/bin` and upgraded maved to 3.0.5. Still getting error. It's definitely a java version issue, I upgraded to java 8 and it worked. Java 6 does not like maven 3.0.5. – Billy Mar 31 '20 at 19:30
  • @Billy I bet there is another problem then JDK 6 <-> Maven 3.0.5 (minimum is here JDK 5)... apart from that do you really need to work on JDK 6 or just produce JDK 6 compatible code? you could use `6` even with JDK 8+... – khmarbaise Mar 31 '20 at 20:40
  • I have the `maven-compiler-plugin` with `1.6`, just produce 1.6 compatible jar. – Billy Mar 31 '20 at 22:01
  • @khmarbaise my co-workers have it working with 3.0.4 maven and java 1.6.0_45, I have 1.6.0_65 jave and maven 3.0.4. Only difference is that I'm on a mac and they're PC. Any anything that would conflict there perhaps? – Billy Mar 31 '20 at 22:06
  • What would help would be full logging output of the maven build ..... – khmarbaise Mar 31 '20 at 22:13
  • @khmarbaise This is the entire output: `COSML-1718672:Desktop bchart545$ mvn -v Exception in thread "main" java.lang.UnsupportedClassVersionError: org/codehaus/plexus/classworlds/launcher/Launcher : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)` Can I enable more detailed logging for this command? – Billy Mar 31 '20 at 22:17
  • I bet you have set a M2_HOME/MAVEN_HOME variable in your environment? (`printenv | grep -i "^M"`)...cause the version 51 is a class which needs Java 7...and the classworlds part is the bootstrap part of Maven itself...Have you set JAVA_HOME? – khmarbaise Mar 31 '20 at 22:21
  • @khmarbaise yep, `JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home` and `M2_HOME=/Users/bchart545/apache-maven-3.0.4`. It's clearly a version issue, but it works for my co-workers which is the most confusing thing to me? – Billy Mar 31 '20 at 22:27

1 Answers1

0

Ok so the only thing that I can think of that I did was go into /usr/local/Cellar/ and delete the maven folder (for the second time) and now it seems to work. Below is my bash_profile:

#set JAVA_HOME
#JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
#JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home
JAVA_HOME=/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
#JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
export JAVA_HOME


M2_HOME=/Users/bchart545/apache-maven-3.0.4
export M2_HOME

PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

export PATH
Billy
  • 1,049
  • 3
  • 14
  • 23