打包war出错

打包war出错

http://img1.sycdn.imooc.com//climg/5d5527520001539110960663.jpg

pom.xml

<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.xu</groupId>

  <artifactId>maven-xu</artifactId>

  <version>1.0.0-list</version>

  <packaging>jar</packaging>

<repositories>

<repository>

<id>aliyun</id>

<name>aliyun</name>

<url>https://maven.aliyun.com/repository/public</url>

</repository>

</repositories>


<dependencies>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.48</version>

</dependency>

</dependencies>

<build>

  <plugins>

    <plugin>

     <groupId>org.apache.maven.plugins</groupId>

     <artifactId>maven-war-plugin</artifactId>

     <version>3.2.2</version>  

    </plugin>

  </plugins>

</build>

</project>


出错提示


[INFO] Scanning for projects...

[INFO] 

[INFO] --------------------------< com.xu:maven-xu >---------------------------

[INFO] Building maven-xu 1.0.0-list

[INFO] --------------------------------[ war ]---------------------------------

[INFO] 

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-xu ---

[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 0 resource

[INFO] 

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-xu ---

[INFO] Nothing to compile - all classes are up to date

[INFO] 

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-xu ---

[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 0 resource

[INFO] 

[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-xu ---

[INFO] Nothing to compile - all classes are up to date

[INFO] 

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-xu ---

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 2.930 s

[INFO] Finished at: 2019-08-15T17:32:07+08:00

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project maven-xu: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test: org/apache/commons/lang3/StringUtils

[ERROR] -----------------------------------------------------

[ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.12.4

[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

[ERROR] urls[0] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/plugins/maven-surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar

[ERROR] urls[1] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/surefire/surefire-booter/2.12.4/surefire-booter-2.12.4.jar

[ERROR] urls[2] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/surefire/surefire-api/2.12.4/surefire-api-2.12.4.jar

[ERROR] urls[3] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/surefire/maven-surefire-common/2.12.4/maven-surefire-common-2.12.4.jar

[ERROR] urls[4] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar

[ERROR] urls[5] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/shared/maven-common-artifact-filters/1.3/maven-common-artifact-filters-1.3.jar

[ERROR] urls[6] = file:/C:/Users/Administrator/Desktop/后端/jar/org/codehaus/plexus/plexus-utils/3.0.8/plexus-utils-3.0.8.jar

[ERROR] urls[7] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar

[ERROR] urls[8] = file:/C:/Users/Administrator/Desktop/后端/jar/org/apache/maven/plugin-tools/maven-plugin-annotations/3.1/maven-plugin-annotations-3.1.jar

[ERROR] Number of foreign imports: 1

[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

[ERROR] 

[ERROR] -----------------------------------------------------: org.apache.commons.lang3.StringUtils

[ERROR] -> [Help 1]

[ERROR] 

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR] 

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
好帮手慕珊 2019-08-16 16:47:35

同学,你好!先了解一下你现在的情况,之前创建maven工程有没有报错,还是打war包之后才出问题的?

因为maven是和网络有关,如果网不好也会报错。可以确认一下网络状况,多尝试一下。

下面说一下创建maven工程的步骤,参照这个再做一遍试试。

1、选择菜单File——New——Maven Project

http://img1.sycdn.imooc.com//climg/5d5669fe0001412606550556.jpg

2、如下页面是存储位置,可以选择自己的文件夹,然后点击Next

http://img1.sycdn.imooc.com//climg/5d566a4300019ba306340578.jpg

3、在下面的界面中选择如下选中的内容,然后点击Next

http://img1.sycdn.imooc.com//climg/5d566a85000172b906330582.jpg

4、然后填写相关内容,点击Finish

http://img1.sycdn.imooc.com//climg/5d566ac20001f1c106370577.jpg

5、我这里建完后是有错误的,jsp文件报错。

http://img1.sycdn.imooc.com//climg/5d566b370001966903510307.jpg

6、打开indexjsp,提示在Java Build Path中没有HttpServlet.

http://img1.sycdn.imooc.com//climg/5d566b6400013cfa05660160.jpg

可以鼠标右键工程,选择Build Path——Configure Build Path,在打开的界面中选择Add Library

http://img1.sycdn.imooc.com//climg/5d566c2b0001a9af09250557.jpg

然后选择Server Runtime

http://img1.sycdn.imooc.com//climg/5d566c4d0001a02605170505.jpg

在如下界面中,选择你的Tomcat服务器,点击OK。如果这里没有服务器,可以提前创建好

http://img1.sycdn.imooc.com//climg/5d566c6a0001a22305210509.jpg

点击Finish,返回上一级页面,然后选中下面的内容,点击Remove,将J2SE 1.5移除

http://img1.sycdn.imooc.com//climg/5d566cc80001fae609240556.jpg

然后选择Add Library,添加JDK 8,此时选择JRE System Library

http://img1.sycdn.imooc.com//climg/5d566d14000148a105200519.jpg

点击Next后,选择Workspace默认的JRE,然后点击Finish

http://img1.sycdn.imooc.com//climg/5d566d320001dc7005660514.jpg

配置完的效果如下,选择Apply,此时错误就消失了,并且运行程序是没问题的。

http://img1.sycdn.imooc.com//climg/5d566d550001e78109260561.jpg

如果创建工程没问题了,再试试打war包。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

好帮手慕珊 2019-08-16 09:57:25

同学,你好!在pom.xml文件中写上如下代码再试试。

<plugin>  
       <groupId>org.apache.maven.plugins</groupId>  
       <artifactId>maven-surefire-plugin</artifactId>  
       <version>2.4.2</version>  
       <configuration>  
         <skipTests>true</skipTests>  
       </configuration> 

 </plugin>

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 L1000 #1
    还是报错,,,,,
    2019-08-16 10:03:09
  • 提问者 L1000 #2
    新建一maven web项目都报错
    2019-08-16 10:05:21
  • 提问者 L1000 #3
    你好,方便远程看看吗?QQ1145415775
    2019-08-16 13:34:30
好帮手慕阿满 2019-08-15 18:15:51

同学你好,项目中在报错,建议同学先解决项目的报错问题,再打包项目。

祝:学习愉快~

  • 提问者 L1000 #1
    packing=war这个填写就出错了
    2019-08-15 18:33:16
  • 提问者 L1000 #2
    没写别的,只写了个pom.xml
    2019-08-15 18:33:34
  • 好帮手慕阿满 回复 提问者 L1000 #3
    建议同学将项目中的报错贴一下,方便我们查看具体错误。祝:学习愉快~
    2019-08-15 19:04:31
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师