Java 使用 Maven 生成 War 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44297430/
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
Generate War file using Maven
提问by TimeToCodeTheRoad
I have a maven pom as follows:
我有一个 maven pom,如下所示:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MerchantWallet</groupId>
<artifactId>StellarReceive</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>StellarReceive Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.3.8.RELEASE</spring.version>
<jdk.version>1.8</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- hello -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<build>
<finalName>StellarReceive</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I dont see a .war file in the target folder. Can someone please help
我在目标文件夹中没有看到 .war 文件。有人可以帮忙吗
采纳答案by Sergio Gragera
First you must define your project with as packaging of war type:
首先,您必须使用 war 类型的包装定义您的项目:
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>war</packaging>
Then you will need to use the maven plugin to generate the war when compiling:
那么你就需要在编译的时候使用maven插件来生成war:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<webXml>target/web.xml</webXml>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
回答by Mobility
one solution is just to use a maven-war-plugin(https://maven.apache.org/plugins/maven-war-plugin/index.html)
一种解决方案是使用 maven-war-plugin( https://maven.apache.org/plugins/maven-war-plugin/index.html)
回答by R Dhaval
Try running clean installor clean packagemaven command.
尝试运行clean install或clean packagemaven 命令。
Project > run as > run config > maven build in left panel > right click > new > goal > clean install> base directory> select your current project workspace.> apply> run
项目 > 运行方式 > 运行配置 > 左侧面板中的 Maven 构建 > 右键单击 > 新建 > 目标 > clean install> 基目录 > 选择您当前的项目工作区。> 应用 > 运行
same way for clean packageor any other maven command.
clean package或任何其他 Maven 命令的方式相同。
if it gives BUILD SUCCESSthen fine otherwise put that error code here in the question.
如果它给出BUILD SUCCESS那么好,否则把错误代码放在问题中。


