My project using Spring Framework 4.0.0 REALESE and maybe it not working on JDK version 1.5, so i want to change it to SE 1.8. I've tried to update my web project's JRE System library from SE 1.5 to 1.8. But i found out after updating project from Maven, my project automatically return to old version. How can i fix it?
3 Answers
The following settings in our project pom.xml
controls the JDK used for compilation
<properties>
. . .
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.bootclasspath>C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar${path.separator}C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar${path.separator}C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar</maven.compiler.bootclasspath>
. . .
</properties>
Our project is a war artifact. After deployment, the configuration of the application server (in our case it is tomcat) determines the JVM that the app server and the app run under.
(Our environment is a bit special -- we use JVM/JDK 8 but use them with Java 1.7 compatibility mode. You don't have to follow this.)

- 6,562
- 8
- 41
- 71
-
1
-
-
Could i ask more question? If i want to set default JDK 1.8 for create a project using Maven, how can i do? – Thịnh Kều Jan 13 '17 at 17:45
-
I am not sure I understand your question. "Default" for the project? Or "Default" for all future maven projects? – leeyuiwah Jan 13 '17 at 17:49
-
I mean when i create a new project using Maven, the JDK use in project always is JDK SE 8[1.8.0_11]. – Thịnh Kều Jan 13 '17 at 17:50
You can configure the compiler plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8<target>
</configuration>
</plugin>

- 4,158
- 23
- 39
-
Could i ask more question? If i want to set default JDK 1.8 for create a project using Maven, how can i do? – Thịnh Kều Jan 13 '17 at 17:46
Your question is not quite clear, so I answer generally:
First of all you need to decide which Java to use to start Maven. This has some implications as newer Maven and Plugin Versions require a certain version. If you start maven from the IDE this might be even more complicated as the JVM used for the IDE is used for maven unless you overwrite it.
If you do nothing else typically this Java VM is also used to run the Java compiler. So this controls language level, output class version and used system libraries. However sometimes you want to have a different compiler (you should avoid it but you can do this). In this case you can specify that the compile plugin (and some others) use fork mode, and then you specify either the path to a Java or you use a Toolchain (both is described here on SO to any extend)
And finally there is the source level and target version settings of the compiler.
This also governs for example the source level and "system libraries" Eclipse will use for the project (use Alt+F5 to re-read it). Eclipse extracts those from the maven-compiler-settings, you typically specify them as POM properties.
And finally don't forget the Java actually used to start your project or app server.

- 10,103
- 1
- 59
- 71
-
First thanks for your answer but configure from POM file not work for me. My web project now running on J2SE-1.5 and i want it runs on J2SE-1.8. How i do it: I right clicked on my project and choose configure class path. Then i remove the old version and add a new version. But when i choose the Maven->Update project, my project return to old version. So the question i want to ask is how to keep the version that i've changed after updating project. – Thịnh Kều Jan 13 '17 at 14:29
-
Maven starting with 3.3.1 needs Java 7 where Maven till 3.2.5 needs Java 6 and before Java 5. Details can be found here: http://maven.apache.org/docs/history.html. All maven plugins need Java 6 usually starting with 3.0.X versions. Details for the plugins can be found the appropriate Maven plugins page For example for the [maven-install-plugin](http://maven.apache.org/plugins/maven-install-plugin/plugin-info.html). – khmarbaise Jan 13 '17 at 14:43
-
1If you want to configure java 1.8 system libraries in Eclipse you need to make sure that a) eclipse finds/knows a 1.8 environment and that you have `maven.compiler.target` set to 1.8 as a POM property. After refreshing in Eclipse the maven config the project will have the correct system library. (If you change it with the preferences by hand eclipse will forget it the next time it frefreshes the POM). I expanded the answer. This asumes of course Maven project type or (I think) Maven Nature. For non-maven project just switch the jvm in project settings. – eckes Jan 13 '17 at 16:48
-
-
Could i ask more question? If i want to set default JDK 1.8 for create a project using Maven, how can i do? Because maybe my web project still go wrong, Spring not finding controller. Or how can i change to Java SE 8[1.8.0_11], because this version is setted up on my computer. – Thịnh Kều Jan 13 '17 at 17:47
-
Not sure you can change the new project template easily. You have to add the maven.compiler.source and target properties to 1.8. – eckes Jan 14 '17 at 17:34