So I finally got around to having enough time to set up a Java-based DXA connecting to a Content Service in the Amazon cloud.
It was a fun adventure, to say the least, and most of it is due to my rustiness in Java. I have tried with both Eclipse and IntelliJ Idea, and definitely IntelliJ made it a lot simpler by detecting project dependencies and installing them for me – which actually made it harder to get Eclipse to work, as I hadn’t noticed what it had done.
Anyway – below are the steps I followed to get a local instance of DXA running within Eclipse. As with the .NET install, you need to make sure you have a proper firewall configuration allowing communication between yourÂ machine and the CIS, as well as having the right mappings set in Topology Manager (I used the default of “localhost:8080″ for this). I will not cover those steps in this post.
In order to get this to work, you need to:
- Install a Java SDK
- Install Maven
- Install Eclipse
- Install Tomcat
- Install lombok
Download a standard JDK from Oracle’s websiteÂ – I went with whatever was the latest version, 64 bit.
Once it’s installed, make sure you set the JAVA_HOME environment variable in your machine, as Maven will need this.
Test that java is installed by running “java -version”
Head over to Maven’s download pageÂ and download the latest one for windows, unzip it to a location you will rememberÂ and then make sure to add “maven\bin” to your path environment variable.
You can test it by running “mvn -v”
Oddly enough, this was what took me the longest, as for some reason eclipse.org was super slow today. Eventually, this mirror worked the best for me, but YMMV.
You need an app server to run your application, so we’ll be using Tomcat for this. Head over to Tomcat’s download page and get Tomcat 8.5x (I used 8.5.12). Unzip it somewhere you will remember!
Don’t ask me what it is, I didn’t bother checking that other than noticing it was needed (thanks to AlexeyÂ Zarakovskiy from SDL’sÂ DXA team for pointing me in this direction).
Download lombok.jar from here, and then run java -jar lombok.jar
A simple wizard will ask you to identify where your IDE is, enter the path to eclipse, and click “Install/Update”.
Getting the DXA
Now that we’re done with the prerequisites, let’s get our DXA going.
The first thing we need to do is to download it, and we will use maven to do this for us. Below are the steps I followed, if you know what you’re doing, feel free to improvise – if you don’t know what you’re doing, doÂ exactly as I did.
- Create a folder, for instance c:\dev\java-dxa
- In a command prompt or PS shell, go to this folder and type “mvn archetype:generate” (without the quotes, of course)
- On the next prompt, enter “dxa” (again, no quotes!)
- Enter “1”
- Press Enter to accept the default (latest DXA version)
- Enter “com.sdl.dxa” as groupId
- Enter “dxawebapp” as artifactId
- Press Enter to accept the default version
- Press Enter to accept the default package
- Enter Y to confirm
Now you should have a set of subfolders created under c:\dev\java-dxa, and one of them (dxawebapp) will have a pom.xml, which we will need soon.
Let’s get into Eclipse
Open Eclipse and configure Tomcat as a Server:
- Click File -> New -> Other
Type “server” to filter and click Next
(You may have to expand this window), select Tomcat v8.5 server and click Next
Specify the location where Tomcat is installed then click on “Installed JREs”
Click on “Add…”
Select “Standard VM” and click Next
Set the path to the folder where the JDK is installed and click Finish
Optionally, set this new JRE as the default.
Quick recap: we now have the DXA’s maven pom.xml, we have Eclipse and we have Tomcat installed as a server in Eclipse. Time to import the DXA into Eclipse:
- Select File -> Import
Type maven in the filter window and select “Existing Maven Project”
Browse to the location where you downladed the POM to (c:\dev\Java-DXA\dxawebapp in my case) and click Finish.
Wait a few minutes for the import to finish. You now should be able to see in your workspace a “DxaWebApp” project. Let’s add the core module to it.
Right-click the dxawebapp project and select Maven -> Select Maven Profiles
In the window that shows the available profiles, check the box next to “core-module” and click OK.
Next, let’s change the DXA’s context root to be / instead of the default of /dxawebapp. Right click the DXA Web App project again and select Properties (all the way at the end of that menu)
Find the “Web Project Settings” and modify the “Context Root” to /
Last step… you’re almost there!
Edit the cd_client_conf.xml file and enter the URL to your discovery service, as well as the cduser and password to use.
Once that’s done, just right-click the project, select “Run As -> Run On Server”, select the tomcat server that you configured earlier… and wait.
You may see an error on the first attempt, as apparently Eclipse expects Tomcat to be able to launch fully in 45 seconds, and this may not be enough the first time. Just do it again, and you’ll finally see this screen: