Deploy a WAR File in JBoss – 在JBoss中部署一个WAR文件

最后修改: 2018年 8月 16日

中文/混合/英文(键盘快捷键:t)

1. Introduction

1.绪论

In this tutorial, we’re going to have a look at how to deploy a war file on the JBoss server.

在本教程中,我们将看看如何在JBoss服务器上部署一个war文件。

We can deploy the war file either by placing the file in the suitable directory manually or directly from Eclipse.

我们可以通过手动将文件放在合适的目录中,或者直接从Eclipse中部署war文件。

2. Deploying the WAR File by Hand

2.手工部署WAR文件

If we already have the war file and we want to deploy it on JBoss, we can go to the JBoss installation directory at standalone/deployments and paste the file there.

如果我们已经有了war文件,并且想在JBoss上进行部署,我们可以去JBoss的安装目录standalone/deployments,把文件粘贴在那里

There are two modes in which the deployment works:

有两种部署工作的模式。

  • manual: the deployment scanner will not attempt to directly monitor the deployment folder. Instead, the scanner relies on marker files. The user’s addition of a marker file serves as a sort of command telling the scanner to deploy content.
  • auto: the scanner will directly monitor the deployment folder, automatically deploying new content and redeploying content whose timestamp has changed.

We can specify the mode in the configuration file standalone.xml by setting the value of the auto-deploy-zipped attribute to either true or false:

我们可以在配置文件standalone.xml中指定该模式,将auto-deploy-zipped属性的值设置为truefalse:

<deployment-scanner 
  name="default" 
  path="deployments" 
  scan-enabled="true" 
  scan-interval="5000" 
  relative-to="jboss.server.base.dir" 
  auto-deploy-zipped="true" 
  deployment-timeout="60"/>

By default, the value is true. So whenever we place a war file in the deployment folder, it’s deployed automatically. JBoss creates the .deployed marker file automatically which indicates that the content has been deployed.

默认情况下,该值为true。所以只要我们把war文件放在部署文件夹中,它就会自动部署。JBoss会自动创建.deployment标记文件,表明内容已经部署。

However, if we remove the previous deployment before copying a new war file to the deployment folder, JBoss will create an .undeployed marker file suggesting that the deployment has been removed. In that case, we would need to delete the marker file manually for the deployment to begin.

然而,如果我们在复制一个新的war文件到部署文件夹之前删除以前的部署,JBoss会创建一个.undeployed标记文件,暗示部署已经被删除。在这种情况下,我们需要手动删除标记文件以开始部署。

If the value of auto-deploy-zipped is set to false, we’ll need to create the .deployed marker file manually for the deployment to start.

如果auto-deploy-zipped的值被设置为false,我们将需要手动创建.deploy标记文件以开始部署。

3. Using Eclipse to Deploy

3.使用Eclipse进行部署

We can create a dynamic web project in Eclipse, add a JBoss server and then configure the application to run on the server. Internally, Eclipse will create the war file of the application and place it in the JBoss directory. We can create an index.html file and set the welcome-file in web.xml to point to it.

我们可以在Eclipse中创建一个动态Web项目,添加一个JBoss服务器,然后配置应用程序以在服务器上运行。在内部,Eclipse会创建应用程序的war文件,并把它放在JBoss目录中。我们可以创建一个index.html文件,并在web.xml中设置welcome-file指向它。

To test if the application is deployed successfully we can fire up the web browser and try to access the URL in this format: http://localhost:<portnumber>/<projectname>

为了测试应用程序是否部署成功,我们可以启动网络浏览器,并尝试以这种格式访问URL。http://localhost:/

If we see the index page, the application is deployed successfully.

如果我们看到了索引页,那么应用程序就部署成功了。

4. Conclusion

4.总结

In this article, we looked at how to deploy a war file on a JBoss server by working with the deployment folder and using Eclipse.

在这篇文章中,我们研究了如何通过部署文件夹和使用Eclipse在JBoss服务器上部署一个war文件。

We also discussed the auto and manual deployment modes and how they work with JBoss’ marker files.

我们还讨论了自动和手动部署模式以及它们如何与JBoss的标记文件一起工作。