问题
It is possible to change the context path of a web application (war
) in glassfish, but is there any solution to change the context path of an Entreprise application (ear
)?
I tried to change it from glassfish-web.xml
like this:
<!-- Default context -->
<context-root>/module1-web</context-root>
<!-- New context -->
<context-root>/erp/module1-web</context-root>
but it does not work. I tried to change it from the server but there is no way to change it.
Web application context path
Is there any solution for that problem?
Thank you.
回答1:
Yes there is a solution for your problem.
You need to place a file named application.xml
in the META-INF
folder of your EAR.
Here is an example how the file could look like:
<?xml version="1.0" encoding="UTF-8"?>
<application 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" version="6">
<application-name>your_application</application-name>
<display-name>your_application</display-name>
<module>
<web>
<web-uri>your-war-file.war</web-uri>
<context-root>/your_desired_context</context-root>
</web>
</module>
<module>
<web>
<web-uri>another-war-file.war</web-uri>
<context-root>/another/context/for/the/second/war/file</context-root>
</web>
</module>
<module>
<ejb>ejb-module-example.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
As you see you can also declare multiple web modules with different context paths.
You can generate the file with the maven-ear-plugin, for more information have a look at this.
Here is an example how to use the plugin:
To make it work, you have to separate your web module (the WAR) to an extra maven project. Then you can reference it in the plugin configuration like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<applicationName>your_application</applicationName>
<modules>
<webModule>
<groupId>com.yourcompany</groupId>
<artifactId>your-web-module</artifactId>
<contextRoot>/your-web-module</contextRoot>
<excluded>false</excluded>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
来源:https://stackoverflow.com/questions/39246145/change-context-path-of-an-entreprise-application-ear-in-glassfish