The following is what I learned about working with the JakartaEE Examples. While anyone can clone the code from the GitHub repository you must be a member of the project to submit new code. You can learn about it at https://projects.eclipse.org/proposals/jakarta-ee-examples.
The examples use embedded server containers that require Java 1.8. Your first step is to place Java 1.8 on your system if it is not already there. I recommend downloading just the zip file of the most recent 1.8 JDK and then unzip it into the location of your choosing. I place mine in “C:\Program Files\Java\”. Obviously it will look very different on a Mac or Linux system.
I do not use an installer because I have other versions of Java on my system and do not want an installer to mess with environment variables or the Windows registry. I assume Mac and Linux users will feel the same minus the Windows registry concern.
If you plan to write and test only Java 11 compliant servers then install Java 11.
I am currently using NetBeans 12 beta 03. It is configured to run under Java 14. I did not need to change this for NetBeans but your IDE may work differently.
Now you are ready to get the examples. Clone the https://github.com/eclipse-ee4j/jakartaee-examples repository.
Once cloned and opened in your IDE you will need to indicate that it must compile and run under Java 1.8. With NetBeans you will right mouse click on the project and configure the Properties -> Compile to Java 1.8 by using the Manage Java Platforms and Add Platform… Here you can navigate to your Java 1.8 installation and NetBeans will now register the project to compile and execute under 1.8. Follow these steps for Java 11 if that is your preference. You cannot use Java 9, 10, 12, 13, 14 or 15. Java 17 will likely be the next version of Java that servers will be updated to.
Bug in parent pom.xml
</systemPropertyVariables>> Notice the extra >
These examples use the Arquillian test container. It will automatically download, using ArquillianChameleon, an embedded version of the server you wish to test against. This means you do not have to install servers for testing. ArquillianChameleon reads the JAVA_HOME environment variable to determine which version of Java it expects to run the embedded container in. Even if your IDE is configured for Java 1.8, if JAVA_HOME shows Java 11, then only an embedded container that is Java 11 compliant will work. Otherwise, you will receive a meaningless error message when Arquillian tries to start the embedded server after downloading it. Change your JAVA_HOME to the folder where Java 1.8 or 11 exists depending on the server you wish to test.
Now its time to see if everything works. Go to the JakartaEE Examples project and use Run Maven or your IDE’s equivalent and in the dialog that appears set the Goals to “clean test” and the Profile to the server you want to use. You can find some that are configured in the profiles section of the parent pom.xml. You want the <id> for the server profile you want to use. I use “payara5”. If it all works, all 113 tests should execute successfully after each project is built. Be patient, it will take a bit of time. Whatever IDE you use make sure that you set the profile otherwise the tests won’t run.
Each of the example projects can be opened to examine. It’s a two or more-step process. First, right mouse click on the project in JakartaEE Examples and select Open Project. What will open will have a Modules folder and in this folder you will find more projects. Think of the first project you opened as the category or type of example and now you need to open the actual project with the code. Right mouse click on the project in Modules you want to examine and choose Open Project. In some cases, you will have another Modules folder and more items to open to get to a normal maven project with source code. You can also run the tests of an individual project like you did for the entire Examples project.
If you plan to create new examples, please follow the model of these projects. You need testing and by examining how they are written for the examples you should be able to easily write your own. I am working on new examples now and if I discover anything else you should know I will write it up.
Shout out to the project lead Arjan Tijms, committer Manfred Riem and mentor Wayne Beaton for their great work on the project.
Now go show us how to code Jakarta EE programs!
NetBeans 12 Beta 03 – what follows is a know issue with this version and will be fixed for the release version.
I experienced a problem that I have been told is a NetBeans issue to be resolved. When I loaded the project the parent pom.xml declared an error. It happened in this section:
<dependency> <groupId>org.arquillian.universe</groupId> <artifactId>arquillian-junit</artifactId> <scope>test</scope> <type>pom</type> </dependency> <dependency> <groupId>org.jboss.arquillian.protocol</groupId> <artifactId>arquillian-protocol-servlet</artifactId> <scope>test</scope> </dependency>
The code would not compile because there was not a version number for these two dependencies. This should not be a problem because the Arquillian BOM supplies this info. However the pom.xml is invalid so the BOM cannot be processed. The solution is to provide a version. Here is what I used:
<dependency> <groupId>org.arquillian.universe</groupId> <artifactId>arquillian-junit</artifactId> <scope>test</scope> <version>126.96.36.199</version> <type>pom</type> </dependency> <dependency> <groupId>org.jboss.arquillian.protocol</groupId> <artifactId>arquillian-protocol-servlet</artifactId> <version>1.1.15.Final</version> <scope>test</scope> </dependency>
Once you successfully compile the project so that the BOM is in your local repository you can go back and delete the version tags.