问题描述
因此,我的企业项目名称 TestProject
,其中包含 TestProject-ejb
和 TestProject- war
,所以当我运行这个项目时,url就像这个 locahost:8080 / TestProject-war
。我如何将这个URL改为 localhost:8080 / testproject
。我使用netbean 6.9,我试图右键单击netbean中的 TestProject-war
文件夹,并在 Run $ c下指定上下文路径$ c>,但它仍然加载
locahost:8080 / TestProject-war
您需要检查EAR的META-INF目录下的application.xml文件中的web模块的上下文根元素是否已正确更改。
<?xml version =1.0encoding =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_IDversion =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>
在这个例子中,web模块应该在您部署的服务器的/ testproject下可用,所以在你的情况 http:// localhost:8080 / testproject
。
$ b (如果你想部署到服务器的根目录,可以将上下文根元素留空:< context-root>< / context-root>
。)
如果您确实看到您在Netbeans中的操作已正确更改此文件,则可能是BalusC所示的部署问题。检查EAR部署到的位置并手动检查部署的版本是否也具有正确的值。
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
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.
这篇关于如何更改我的企业项目的上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!