maven 打包war包遇到的问题

1 项目标示红叉,problems中提示:“Dynamic Web Module 3.0 requires Java 1.6 or newer.”

原因:maven项目中, "Maven uses 1.5 as default compiler independently of the version you have in your JAVA_HOME or eclipse"--来自overflow

解决方法:在pom.xml中添加以下,并执行maven-update project

<plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-compiler-plugin</artifactId>  
            <version>2.3.2</version>  
            <configuration>  
                <source>1.7</source>  
                <target>1.7</target>  
            </configuration>  
</plugin>

2 执行run-maven install 报错 “Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)”

原因:maven 找不到web.xml,需要显式的告诉它路径,

解决方法:在pom.xml中配置:

<plugin>
           <artifactId>maven-war-plugin</artifactId>
           <configuration>
                <version>2.5</version>
                <webXml>src\webapp\WEB-INF\web.xml</webXml>
           </configuration>
 </plugin>

3 打包好的war中,缺少了js/css/jsp等内容

原因:maven打包"default maven war pluggin uses the source directory to package the war",需要指定maven打包source目录

解决方法:在pom.xml中配置:

<plugin>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <version>2.5</version>
                <warSourceDirectory>src\webapp</warSourceDirectory> 
           </configuration>
</plugin>


猜你喜欢

转载自blog.csdn.net/xlnhaha/article/details/80538421