把 java web application deploy 到 root

本文介绍了两种在Tomcat中将应用程序部署到根目录的方法:一种是直接将WAR包重命名为ROOT.war;另一种是在server.xml中配置Context元素来指定应用的上下文路径为空。

http://stackoverflow.com/questions/5328518/deploying-my-application-at-the-root-in-tomcat

You have a couple of options:

  1. Remove the out-of-the-box ROOT/ directory from tomcat and rename your war file to ROOT.war before deploying it.

  2. Deploy your war as (from your example) war_name.war and configure the context root in conf/server.xml to use your war file :

    <Context path="" docBase="war_name" debug="0" reloadable="true"></Context>

The first one is easier, but a little more kludgy. The second one is probably the more elegant way to do it.

转载于:https://www.cnblogs.com/johnsonshu/p/5704629.html

<think>嗯,用户想了解如何使用Maven将Web项目部署到WebSphere。我需要先回忆一下相关的步骤和注意事项。首先,用户可能已经有一个基于Maven的Web项目,但需要配置部署到WebSphere。WebSphere作为传统的应用服务器,部署方式可能和Tomcat之类的有所不同,尤其是通过Maven的情况。 首先,我得考虑Maven插件。可能常用的有was-maven-plugin,或者需要配置Cargo插件?记得WebSphere可能需要特定的配置,比如连接方式和管理控制台的参数。另外,WebSphere的管理SOAP端口通常是8880或8881,用户需要确认自己环境的正确端口。 然后,用户可能需要配置server.xml或者pom.xml中的插件信息。需要添加插件依赖,并设置正确的服务器ID、主机名、端口、应用名称等。可能还需要提供管理员账号密码,这些通常会放在Maven的settings.xml里,避免明文出现在项目中。 接下来,部署命令应该是mvn clean install was:deploy或者类似的。但用户需要注意,WebSphere可能需要先启动部署管理器,节点agent等,确保服务正常运行。另外,应用部署后的启动问题,可能需要手动启动或者通过插件参数控制。 可能遇到的常见问题包括类加载策略、父最后(parentLast)的设置,避免类冲突。还有JDK版本是否匹配,WebSphere的版本是否与插件兼容。比如,旧版WebSphere可能需要特定的插件版本,或者额外的配置步骤。 此外,用户可能想知道除了Maven插件之外的其他部署方式,比如通过控制台手动部署WAR文件,或者使用wsadmin脚本自动化。这些可以作为替代方案补充说明,让用户有更多选择。 需要提醒用户检查WebSphere的安全设置,确保Maven插件有权限访问管理控制台。防火墙设置是否开放了相应端口,管理员账户是否正确,避免连接失败。 最后,整理步骤时要注意逻辑顺序,先配置插件,设置参数,再执行命令,然后验证部署结果。可能还需要在pom.xml中示例插件配置,让用户能直接参考。同时,强调配置文件的安全性,比如不要在代码库中暴露密码,而是使用Maven的加密机制或settings.xml中的服务器配置。</think>以下是将Maven Web项目部署到WebSphere的逐步指南: 一、前期准备 1. 确认环境 - 已安装WebSphere Application Server(传统版本或Liberty) - 配置好WebSphere管理控制台(默认端口9043/9443) - 确保Maven 3.6+ 和JDK版本与WebSphere兼容 2. 项目要求 - 项目使用war打包方式 $$<packaging>war</packaging>$$ 二、配置Maven插件(推荐两种方式) 方式1:使用was-maven-plugin 1. 添加插件配置到pom.xml ```xml <build> <plugins> <plugin> <groupId>com.ibm.websphere</groupId> <artifactId>was-maven-plugin</artifactId> <version>8.5.5</version> <configuration> <serverName>WebSphere_Portal</serverName> <host>localhost</host> <port>8880</port> <!-- SOAP连接端口 --> <applicationName>myWebApp</applicationName> <virtualHost>default_host</virtualHost> </configuration> </plugin> </plugins> </build> ``` 2. 配置认证信息(推荐在settings.xml中设置) ```xml <servers> <server> <id>WebSphere_Portal</id> <username>admin</username> <password>{加密密码}</password> </server> </servers> ``` 方式2:使用Cargo插件(通用方式) ```xml <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven2-plugin</artifactId> <version>1.9.15</version> <configuration> <container> <containerId>websphere9x</containerId> <type>installed</type> <home>${websphere.install.path}</home> </container> <configuration> <type>existing</type> <home>${websphere.profile.path}</home> </configuration> <deployables> <deployable> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <type>war</type> </deployable> </deployables> </configuration> </plugin> ``` 三、部署命令 ```bash # 方式1部署命令 mvn clean package was:deploy # 方式2部署命令 mvn clean package cargo:deploy ``` 四、关键配置注意事项 1. 端口配置 - SOAP连接器端口默认8880(基础版) - Liberty版本默认使用9443端口 2. 类加载策略 ```xml <!-- 在pom.xml中添加 --> <configuration> <classloaderPolicy>PARENT_LAST</classloaderPolicy> </configuration> ``` 3. 部署后验证 - 访问管理控制台:`https://localhost:9043/ibm/console` - 检查应用程序状态是否为"已启动" 五、常见问题解决 1. 连接拒绝 - 确认`管理服务->应用程序服务器->服务器端口`中的SOAP端口 - 检查防火墙设置 2. 类冲突 ```xml <!-- 添加排除配置 --> <configuration> <isolatedClassLoading>true</isolatedClassLoading> </configuration> ``` 3. 版本兼容性 - WebSphere 9.x建议使用插件版本1.0.2+ - Java EE规范需与WebSphere版本匹配 六、替代方案 1. 手动部署: - 通过管理控制台上传war文件 - 使用wsadmin脚本: ```jython AdminApp.install('path/to/app.war', '[ -appname myApp -contextroot / ]') AdminConfig.save() ``` 建议: 1. 生产环境推荐使用Jenkins等CI/CD工具集成部署 2. 对于Liberty版本,可使用`liberty-maven-plugin`简化配置 3. 定期清理旧版本应用: ```bash mvn was:undeploy -Dwas.app.name=myWebApp ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值