英文:
How to use Maven to build a war and use Jenkins to deploy to Tomcat server
问题
我已经创建了一个Servlet项目。项目结构如下:
.
|-- pom.xml
|-- web
| |-- css
| |-- fonts
| |-- image
| |-- js
| |-- css
| |-- WEB-INF
| | `-- web.xml
| `-- index.jsp
`-- src
`-- MyServlet.java
而我的 pom.xml 文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<finalName>web-app-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webXml>web\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
当我尝试运行 mvn war:war
时,我发现它在目标文件夹下创建了一个新的 example.war 文件。然而,这个 example.war 文件是空的。
我想要做的是创建一个 *.war 文件,并通过使用 Jenkins 将这个 *.war 文件部署到 Tomcat。有人知道如何做吗?谢谢!
英文:
I hava create a servlet project. The project structure is like that:
.
|-- pom.xml
|-- web
| |-- css
| |-- fonts
| |-- image
| |-- js
| |-- css
| |-- WEB-INF
| | `-- web.xml
| `-- index.jsp
`-- src
`-- MyServlet.java
And my pom.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<finalName>web-app-name</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webXml>web\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I try to run mvn war:war
, I found it create a new example.war under target folder. However, the example.war is empty.
What I want to do is to create a *.war and deploy this *.war to Tomcat by using Jenkins. Anyone know how to do it? Thanks!
答案1
得分: 1
我认为你没有遵循正确的项目结构。看起来你需要:
项目名
|-- pom.xml
`-- src
`-- main
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
`-- java
英文:
I don't think you're following the correct project structure. It looks like you need:
project
|-- pom.xml
`-- src
`-- main
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
`-- java
See the Maven Archetype for War files
答案2
得分: 0
跟随Ashley的建议。
此外,使用mvn clean verify
构建你的项目。单独运行war插件不起作用。
英文:
Follow Ashley's advice.
Furthermore, build your project with mvn clean verify
. Running the war plugin separately does not work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论