Deal with Context-Path in Java EE

Maybe have you ever try to create an Enterprise Application in Java, containing both EJB and Web modules. And maybe have you noticed that the context-path of the web application is the same that the generated WAR file.
So let’s imagine you create an enterprise application named JustMyApp with two modules: JustMyApp-ejb and JustMyApp-war. After deploying your application, you just go to your website using an URL like this one (depending on which port your server is running): http://localhost:8080/JustMyApp-war. Well I have to admit I totally dislike to enter -war in the URL… Why not JustMyApp only?

Context-Path in Java EE is kind of strange. Indeed, if you only have a WAR (not en EAR) changing the CP for the WAR is working fine. But if you are in an EAR, things are little bit different!

So how to do that? You have to create a file called a Standard Deployment Descriptor and put it into your EAR. The name of this file must be application.xml. This file contains the name of all modules you have in the EAR, and you can specify the context-path for your Web module. Let’s see an example:

<?xml version="1.0" encoding="UTF-8"?>
<application version="6" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
  <display-name>JustMyApp</display-name>
  <module>
    <ejb>JustMyApp-ejb.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>JustMyApp-war.war</web-uri>
      <context-root>/JustMyApp</context-root>
    </web>
  </module>
</application>

The URL to enter to access your web application is just specified by the <context-root>…</context-root> markup. So put there whatever you want and just try it ! That’s how the Context-Path for EAR can be changed !

Enjoy.

UML in NetBeans 6.8

If you try to install an UML plugin for NetBeans using the Plugins window of the application, you won’t find an UML one.
The solution is quite simple. Indeed you just need to download a ZIP file on the NetBeans website. Search for a file named netbeans-6.8-201004041201-ml-uml.zip and download it. Once it’s done, you just need to extract this archive inside the NetBeans installation folder. The result of the extraction should give you a folder named uml6. Restart NetBeans and for now you can create UML projects. It’s cool isn’t it? :)

For Mac users: find your NetBeans.app and right-click on it and choose Show Package Content. Then go to the Contents > Resources > NetBeans folder. Place the uml6 folder here. It’s done.

Enjoy.

Follow

Get every new post delivered to your Inbox.