Home » Language IDEs » Java Development Tools (JDT) » Oxygen.1, Java 9, Maven Dynamic Web Project Guide(Various issues getting everything going)
|Oxygen.1, Java 9, Maven Dynamic Web Project Guide [message #1775111]
||Tue, 24 October 2017 16:46
| Chris St. Onge
Registered: August 2015
So long story short, I've been trying to upgrade my latest project to Java 9. I'll recap what I've done. This is just a guide to assist anybody else so they don't have to spend days trying to get this working.|
Environment consists of Eclipse Oxygen.1(a?) with lombok 1.16.16, Java 9, Tomcat 8.5, Spring 5, and Hibernate 5. This was working fine with Java 1.8.
1) I wanted Eclipse to use the Java 9 VM. In eclipse.ini, add a -vm option just above -vmargs to specify Java 9:
2) Also ensure the following exists in eclipse.ini:
3) Next we need to tell Eclipse about the Java 9 JRE so go to Window -> Preferences -> Java -> Installed JREs and add it.
4) Now we need to upgrade our project to Java 9. However, if your project uses Facets, there is no Java 9 version option for the Java facet. If you search for it, you will find a bug about it and how it is patched in WebTools. If you set the project to use the Java 9 compiler now, Maven will warn that it does not match the Java facet version. Go to Help -> Install New Software and add http://download.eclipse.org/webtools/repository/oxygen/ as an update site.
5) Next I updated Eclipse by going to Help -> Check for Updates. For me, I had issues with a "can't find repository error" so I had to clean up my list of update sites. There were quite a few updates and I am not sure if the Java facet fix was included.
6) Go back to Help -> Install New Software and select the update site you just added. Install the "Web Tools Platform (WTP) 3.9.1a" update. It might say that you already have some parts of the update and when asked make sure you choose to modify the updates to be compatible with your installation. Check the Java facet to make sure 9 is now an option.
7) Maven's pom now has to be updated because I had the Java version specified in the pom under the maven-compiler-plugin entry and this will cause your Java version to revert when you do a Maven update. Change your Java version to 9 in the pom.
8) Check your project build path to make sure the Java 9 JRE is now selected. You will notice your Build Path now has only 2 items: Modulepath and Classpath.
9) Go to Window -> Preferences -> Project Facets and change the Java facet version to 9.
10) Go to Window -> Preferences -> Java Compiler and make sure the compliance level is set to 9.
11) Now we need to deal with missing Java 9 modules, in our case it was java.xml.bind, java.xml.ws.annotations, and java.activation. If you have lombok, you will notice that it can no longer be resolved. Eclipse may try to build your project if you have it set to automatically do so. It will fail and retry over and over again. That's fine. If you look at one of the many build errors, it will say something about a NullPointerException. This is being caused by the missing java.xml.bind module. So let's include the missing modules.
If you search the internet, the most common solution is to use the --add-modules vm argument equivalent by way of going to the Build Path, expanding Modulepath, expanding the JRE, selecting Is modular, clicking Edit, and then adding the 3 modules I listed above. The issue with this is that every time you do a Maven update, it resets these inclusions. Very annoying. I experimented with adding them under the maven-compiler-plugin in a <compilerArgs> element but that didn't seem to do anything. The proper way to do this is to rely on external dependencies through Maven. Think I read that java.xml is deprecated so we shouldn't be using --add-modules to include them anyway. Instead, search Maven for javax.annotation-api, jaxb-api under javax.xml.bind, and javax.annotation-api and add them to your pom as dependencies. You may have to do this for other modules depending on what's in your project.
12) At this point, Eclipse should be using the Java 9 VM and your project should be using the Java 9 compiler. Do a Maven update to fix any errors.
Okay so not everybody uses this but I can't stand writing, generating, or even seeing default getters/setters anymore. The latest version of lombok I could get working with Oxygen was 1.16.16. In addition to having the lombok JAR in the Eclipse folder, and the -javaagent:lombok.jar entry at the bottom of eclipse.ini, I also had to add an entry for lombok in the project pom like so:
Do a Maven update and you should be good to go.
I was hoping Tomcat 9 would have released by now but at the time of this writing, it's still in beta. Oh well.
Since Java 9 is now all about modules, some Tomcat libraries depend on java.xml.bind (SqlServer drivers for one) and Tomcat will throw NoClassDefFoundErrors on startup. We could add --add-modules=java.xml.bind as a launch argument but since it seems that package is deprecated, why not use the javax.xml.bind instead? I downloaded the JAR from Maven and dropped it in Tomcat's lib folder and it worked.
You may see a warning like "WARNING: An illegal reflective access operation has occurred". This is a Spring bug and adding
as a launch argument will hide it.
**On a side note, there was a bug in Oxygen before Oxygen.1 where Tomcat servers controlled by Eclipse failed to start. This was because Eclipse was hard-coded to add a -dirs launch argument but Java 9 no longer supports it. You could remove the argument but Eclipse would just add it again on startup. Anyway, it was fixed for this release of Oxygen.
Current Time: Fri Dec 15 10:31:48 GMT 2017
Powered by FUDForum
. Page generated in 0.01502 seconds