Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the context path of my Enterprise Project

So my enterprise project name TestProject, which contain TestProject-ejb and TestProject-war, so when I run the project the url is like this locahost:8080/TestProject-war. How can I change this url to localhost:8080/testproject. I use netbean 6.9, I try to right click on TestProject-war folder in netbean, and specify the context-path there under Run, but it still load locahost:8080/TestProject-war

like image 876
Thang Pham Avatar asked Jan 21 '11 12:01

Thang Pham


3 Answers

You need to check that the context-root element for the web module in the application.xml file that's in the META-INF directory of your EAR has been correctly changed.

An example would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
    id="Application_ID" version="6">

    <display-name>TestProject</display-name>

    <module>
        <web>
            <web-uri>TestProjectWeb.war</web-uri>
            <context-root>testproject</context-root>
        </web>
    </module>

    <module>
        <ejb>TestProjectEJB.jar</ejb>
    </module>

</application>

In this example the web module should be available under /testproject of the server you deploy to, so in your case http://localhost:8080/testproject.

(In case you would like to deploy to the root of your server, you can leave the context-root element empty: <context-root></context-root>.)

If you indeed see that your action in Netbeans has correctly changed this file, it may be a deployment problem like BalusC indicated. Check the location the EAR is deployed to and manually inspect whether the deployed version also has the correct value.

like image 109
Arjan Tijms Avatar answered Oct 14 '22 00:10

Arjan Tijms


As Harry pointed out the default project template doesn't create an application.xml file, so you have to create it by hand at $ENTERPRISE_APP_PATH/src/conf (tested with NB 6.9.1)

like image 39
Charles Bedon Avatar answered Oct 14 '22 02:10

Charles Bedon


Just ran into this question in the course of figuring out the same thing. Since the OP was asking about doing this in Netbeans, let me add to previous answers by describing specifically how to do this using the Netbeans IDE.

With Netbeans 8 (and possibly also with earlier versions) you can tell the IDE to create the application.xml file for you, as follows. Right-click the enterprise application project (in the OP's example this would be "TestProject"), select "New" then "Standard Deployment Descriptor...". This will create an "application.xml" file and put it in the appropriate place in your Netbeans project. Then you can easily edit this file to set the context-root element to be whatever you want.

like image 1
Duncan Avatar answered Oct 14 '22 01:10

Duncan