在Glassfish中更改企业应用程序(ear)的上下文路径 [英] Change context path of an Entreprise Application (ear) in glassfish
问题描述
可以在glassfish中更改Web应用程序(war
)的上下文路径,但是有什么解决方案可以更改Entreprise应用程序(ear
)的上下文路径吗?
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
)?
我试图像这样从glassfish-web.xml
更改它:
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应用程序上下文路径
该问题有解决方案吗?
谢谢.
推荐答案
是的,您的问题有解决方案.
Yes there is a solution for your problem.
您需要在EAR的META-INF
文件夹中放置一个名为application.xml
的文件.
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>
如您所见,您还可以声明具有不同上下文路径的多个Web模块.
As you see you can also declare multiple web modules with different context paths.
您可以使用 maven-ear-plugin 生成文件,有关更多信息,请参见此.
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:
要使其工作,您必须将Web模块(WAR)分离到一个额外的maven项目中.然后,您可以在插件配置中引用它,如下所示:
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>
这篇关于在Glassfish中更改企业应用程序(ear)的上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!