As I have said, Maven doesn't use PATH but uses the JAVA_HOME environment variable.
That's all about how to specify the Java version for Maven in Windows. Btw, if you want to learn about Maven itself, I suggest you take a look at these Apache Maven courses, one of the better courses to start with Maven. This solution is really nice as you don't need elevated access and can solve the problem immediately. It will not affect your machine's JAVA_HOME settings and will go away as soon as you close the shell or open a new shell. The change will be temporary and only applicable to the shell you are running. $ set JAVA_HOME= path- to-jdk- bin- directory You can still change the JAVA_HOME environment variable in the local shell you are running the maven command by using the "set" command as shown below: If you are also stuck in a similar situation, don't worry.
The solution was easy in my case but one of my readers reported that he can't change an environment variable in his PC without elevated access or calling Desktop support, which happens mainly in a big organization like Investment banks. How to specify Java Version for Maven in Command prompt
You can check these Java Programming Courses to learn more about class files and how Java works in general.
minor version 52.0 error while building your project or any open source project using Maven, please check the JAVA_HOME environment variable in your machine and change it to JDK 1.7 or JDK 1.8 depending upon the error you are getting. If you are getting the Unsupported major.minor version 51.0 or Unsupported major. So, just remember that Maven doesn't use PATH to pick the Java version, instead, it uses the JAVA_HOME variable. The solution was now easy, I just updated JAVA_HOME and it worked fine. To confirm the JAVA_HOME, I checked the environment variable using the "env" shell command on Windows, and boom, it was pointing to JDK 1.6 which explains the error. Then I realized that when you type java on command prompt it picks the JDK version from the PATH environment variable but Maven uses the JAVA_HOME environment variable to pick the JDK version to build your project and run it's a plugin. 181- b32, mixed mode)Īnd it was declaring the correct Java version. Java HotSpot(TM) 64- Bit Server VM ( build 25. Java version "1.8.0_181" Java(TM) SE Runtime Environment ( build 1. To confirm that I run the following command in the command line window I was using to run Maven: I was surprised by this error because I was sure that I am using Java 1.8, which should be enough to build the project. I was getting "org/apache/maven/plugins/resources/ResourcesMojo : Unsupported major.minor version 51.0" error which means Maven is using JDK 1.6 or lower to build the project but the project needed Java 1.7 (See my article on UnsupportedClassVersion to learn more). In order to do that I cloned the latest release of QuickFIX from GitHub and started building using Maven, only for the build to be failed. I had a requirement to add a custom FIX tag to parse the incoming messages and for that, I need to extend the FIX dictionary of QuickFIXJ (like a FIX44.xml file) and build the JAR file.
If you are interested, you can learn more about the FIX in my series of FIX tutorials. If you don't know the FIX, it stands for Financial Information Exchange protocol and is used heavily for Electronic trading. Recently I got a chance to work with QuickFIXJ, an open-source library to parse and process FIX messages.
I'll tell you how to do that in this article. This change will not affect the entire machine and go away as soon as you close the shell. If you don't have access to do it then you can still change JAVA_HOME using the set command in your local shell and run the Maven's mvn command to build the project
If you have multiple JDK installed on your machine and getting an Unsupported major.minor version 51.0 or Unsupported major.minor version 52.0 error while building your project but have right Java version in PATH then you may need to check the JAVA_HOME and update it. One of them is that Maven uses the Java version from the JAVA_HOME environment variable and not the PATH environment variable. Maven is a great build tool and most of the Java developer uses Maven to build their projects, but like any other tool, there are some intricacies which you need to know while using it.