Java 如何将 root(/) 上下文中的 war 文件部署到 Wildfly 9.0.1 版
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32241906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to deploy war file in root(/) context to Wildfly ver 9.0.1
提问by Vartika
I am newbie for Wildfly till now I was working on tomcat to deploy my applications. Now just for add on features of Wildfly we want to move on to this.
I am using Windows Os, I have done with the basic implementation of wildfly to start service etc. but Unable to deploy the ROOT.war in place of Welcome page. I have studied and gone through lot of links, I added jboss-web.xml in my project WEB-INF folder with following settings as I got in links.
But I am still unable to deploy the ROOT.war in standalone deployment. Each times it goes to failed. Not getting what I have done Wrong.
我是 Wildfly 的新手,直到现在我一直在使用 tomcat 来部署我的应用程序。现在只是为了添加 Wildfly 的功能,我们想继续这个。我使用的是 Windows 操作系统,我已经完成了 Wildfly 的基本实现以启动服务等,但无法部署 ROOT.war 来代替欢迎页面。我已经研究并浏览了很多链接,我在我的项目 WEB-INF 文件夹中添加了 jboss-web.xml,并在链接中添加了以下设置。但是我仍然无法在独立部署中部署 ROOT.war。每次都失败了。没有得到我所做的错误。
`<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>`
I have made the admin user, But for deploying I am using wildfly user setting only. For it also I uncommented the fields from bin/init.d wildfly.conf fly. But totally unaware of the error.
我已经创建了管理员用户,但是为了部署,我只使用了wildfly 用户设置。为此,我也取消了 bin/init.d wildfly.conf fly 中的字段的注释。但完全不知道错误。
Note:We also tried it on linux machine but ROOT.war is not getting deployed there too.used
注意:我们也在 linux 机器上尝试过,但 ROOT.war 也没有在那里部署。用过的
采纳答案by Vartika
two files have to be added in WEB-INF folder before making war file 1. jboss-web.xml
在制作war文件1.jboss-web.xml之前,必须在WEB-INF文件夹中添加两个文件
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/</context-root>
</jboss-web>
- empty bean.xml
- 空bean.xml
回答by Phuthib
The welcome page has a note at the bottom,
欢迎页面底部有一个注释,
To replace this page set "enable-welcome-root" to false in your server configuration and deploy your own war with / as its context path.
要替换此页面,请在您的服务器配置中将“enable-welcome-root”设置为 false,并使用 / 作为其上下文路径部署您自己的战争。
Please confirm if you did set the enable-welcome-root to false.
请确认您是否将 enable-welcome-root 设置为 false。
Hope that helps
希望有帮助
回答by Douglas De Rizzo Meneghetti
If you are using Maven to deploy your application, you can change the default war file name in your pom.xml
to ROOT like this:
如果您使用 Maven 来部署您的应用程序,您可以pom.xml
像这样将您的默认 war 文件名更改为 ROOT:
...
</dependencies>
<build>
<!-- <finalName>${project.artifactId}</finalName> -->
<finalName>ROOT</finalName>
When you deploy your application using Maven, Wildfly will automatically host it under /
. This way, you prevent changing the name of the war file yourself.
当您使用 Maven 部署应用程序时,Wildfly 将自动将其托管在/
. 这样,您就可以防止自己更改战争文件的名称。
回答by stefv
To override the welcome webapp with Wildfly, you need to create a jboss-web.xml
in the WEB-INF
of your webapp with this content:
要使用 Wildfly 覆盖欢迎 Web 应用程序,您需要使用以下内容jboss-web.xml
在您的 Web 应用程序中创建一个WEB-INF
:
<jboss-web>
<context-root>/</context-root>
</jboss-web>
But if you try to access to the root directory (e.g. http://localhost:8080/) you will still have the default welcome content. To remove it, you just need to rename the directory welcome-content
in the Wildfly directory.
但是,如果您尝试访问根目录(例如http://localhost:8080/),您仍将拥有默认的欢迎内容。要删除它,您只需要重命名welcome-content
Wildfly 目录中的目录。
回答by Young
For my wildfly 9.0.1 deployment, we did the following two and it worked.
对于我的 wildfly 9.0.1 部署,我们做了以下两个并且成功了。
jboss-web.xml as described above by other experts.
In standalone.xml,
<host name="default-host" alias="localhost, myAppDomain.com" default-web-module="myApp.war"> <location name="/" handler="welcome-content"/> <filter-ref name="server-header"/> <filter-ref name="x-powered-by-header"/> </host>
jboss-web.xml 如上面其他专家所述。
在standalone.xml中,
<host name="default-host" alias="localhost, myAppDomain.com" default-web-module="myApp.war"> <location name="/" handler="welcome-content"/> <filter-ref name="server-header"/> <filter-ref name="x-powered-by-header"/> </host>
回答by user1593165
If your web module is inside an ear you can you the following syntax
如果您的网络模块在耳朵内,您可以使用以下语法
<host name="default-host" alias="localhost" default-web-module="myApp.ear.myWebApp.war">