Friday, December 14, 2012

Building a Java EE application with Intellij (and Windows)

We are going to use Intellij to build our photodb project (Check Getting started with Apache TomEE by Jonathan Gallimore to see an example with Eclipse). By using an IDE to build and run the application, we make this a multi-platform task, meaning that the Windows users can follow the same steps as Ubuntu ones. In fact, I will use a Windows box for this demo. I won't install the tools. I will assume that you have a computer with the following software already installed.
Open the IDE and select "Check out from Version Control" and then "Git".



Set the Git parameters, click "Clone" and then "No".
  • https://github.com/tveronezi/photodb.git
  • C:\Users\tveronezi\dev\ws
  • photodb


We hit "No" because we want to hack the way Intellij imports Maven projects, otherwise we will see an extra generated folder (Intellij stuff) under the photodb root directory.

Now hit "Import Project", navigate to the photodb directory and click "Ok".



Select "Import project from external model", "Maven" and click "Next".


Select "Keep project files in", point it to another directory and click "Next".



Click "Next" again.



Select the JDK that you want to use in the project (Add one if necessary).


Click "Next" and then "Finish".



Now lets prepare the Application Server. We will use the bleeding edge version of TomEE. You can either build your server locally or download it here [I've already built it for you ;O)]. Now extract it to a directory of your choice.

Click on "Edit Configurations..."



Add a new configuration.



Select "TomEE Server" and "Local"



Click "Configure" and set the path of your TomEE installation.



Select the "Deployment" tab, click "Add" and "Artifact".



Select "photodb-gui:exploded".


Change the "Application Context" to "/photodb".



We are almost there. We still need to configure the JAAS. Copy "photodb/src/main/config/localLoginScript.js" to the config folder of your TomEE installation. Now add an environment variable to TomEE.


The variable is "CATALINA_OPTS" and the value is...

Djava.security.auth.login.config=C:\Users\tveronezi\dev\ws\photodb\src\main\config\login.config


Now start your server...


In a few seconds you should see an opened browser. The user is "michael" and the password is "test".


Add some photos...


That's it! 10 minutes to prepare our development environment. :O)