正在回答
同学你好,1、在后面的课程中,会根据在案例中体现使用maven创建项目的过程,同学可以参考学习,如果现在同学想在idea中创建web项目,可以按照本小节课程中的步骤创建项目后,再创建一个webapp目录,然后根据如下步骤将webapp添加到项目目录中:
1)
2)
3)
4)
5)
6)
完成如上步骤后,当前项目的webapp目录就创建好了,这就是一个maven的web工程
2、怎么打成war包
在pom.xml文件中添加如下配置
配置完成后,使用idea的打包命令打包
打包完成后,就是一个war包。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
同学你好,根据同学贴出的报错信息以及项目截图,同学创建的webapp目录是不正确的,webapp的图标不是这样显示
而同学展示的是普通文件夹是这样的
所以,对应问题就是找不到在webapp目录下的WEB-INF/web.xml的内容。
同学可以删除当前的web目录,按照之前的步骤再次操作创建webapp目录,注意在操作如下步骤时,右侧有上下两部分,可以选中后点击修改,按照自己项目中的路径去选择,这一步其实就是告诉IDEA自己的web根目录是什么。自己的web.xml文件在何处。
如上操作有,查看自己的webapp的图标是否是正确配置了。配置成功后,再来重试打包一下
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
"C:\Program Files\Java\jdk1.8.0_221\bin\java.exe" "-Dmaven.multiModuleProjectDirectory=D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven" -Xms128m -Xmx512m -Dmaven.home=D:\apache-maven-3.6.1 -Dclassworlds.conf=D:\apache-maven-3.6.1\bin\m2.conf "-javaagent:D:\IntelliJ IDEA 2018.2.8\lib\idea_rt.jar=64592:D:\IntelliJ IDEA 2018.2.8\bin" -Dfile.encoding=UTF-8 -classpath D:\apache-maven-3.6.1\boot\plexus-classworlds-2.6.0.jar org.codehaus.classworlds.Launcher -Didea.version=2018.2.8 -s D:\apache-maven-3.6.1\conf\settings.xml package [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.imooc:MyFirstMaven >----------------------- [INFO] Building MyFirstMaven 1.0.0.RELEASE [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MyFirstMaven --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MyFirstMaven --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 3 source files to D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\target\classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MyFirstMaven --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MyFirstMaven --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 1 source file to D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\target\test-classes [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ MyFirstMaven --- [INFO] Surefire report directory: D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.imooc.TestMybatis {zwid=2, flname=��������, money=12345.0, zhanghu=�ֽ�, createtime=2016-03-15, description=��������} {zwid=3, flname=��װ֧��, money=1998.0, zhanghu=�ֽ�, createtime=2016-04-02, description=���·�} {zwid=4, flname=�Է�֧��, money=325.0, zhanghu=�ֽ�, createtime=2016-06-18, description=���Ѿ۲�} {zwid=5, flname=��Ʊ����, money=8000.0, zhanghu=��������, createtime=2016-10-28, description=��Ʊ����} {zwid=6, flname=��Ʊ����, money=5000.0, zhanghu=��������, createtime=2016-10-28, description=��Ʊ�ִ���} {zwid=7, flname=��������, money=5000.0, zhanghu=��������, createtime=2016-10-28, description=�ֿ�������} {zwid=8, flname=���֧��, money=5000.0, zhanghu=�ֽ�, createtime=2016-10-28, description=���ѽ��} {zwid=9, flname=����֧��, money=1560.0, zhanghu=�ֽ�, createtime=2016-10-29, description=��Ǯ��} {zwid=10, flname=��֧ͨ��, money=2300.0, zhanghu=��ͨ����, createtime=2016-10-29, description=�ͼۻ�����} {zwid=11, flname=�Է�֧��, money=1000.0, zhanghu=��������, createtime=2016-10-29, description=�ֳԷ�} {zwid=12, flname=��������, money=1000.0, zhanghu=�ֽ�, createtime=2016-10-30, description=����} {zwid=13, flname=��֧ͨ��, money=2000.0, zhanghu=�ֽ�, createtime=2016-10-30, description=��Ʊ�ù�} {zwid=14, flname=��Ʊ����, money=3000.0, zhanghu=�ֽ�, createtime=2020-01-01, description=����̫����} {zwid=15, flname=��Ʊ����, money=3000.0, zhanghu=�ֽ�, createtime=2020-01-01, description=����̫����} {zwid=16, flname=��Ʊ����, money=3000.0, zhanghu=�ֽ�, createtime=2020-01-01, description=����̫����} {zwid=17, flname=���²���, money=3000.0, zhanghu=�ֽ�, createtime=2020-01-01, description=����̫����} 0 Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.521 sec Results : Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:3.2.2:war (default-war) @ MyFirstMaven --- [INFO] Packaging webapp [INFO] Assembling webapp [MyFirstMaven] in [D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\target\MyFirstMaven-1.0.0.RELEASE] [INFO] Processing war project [INFO] Webapp assembled in [634 msecs] [INFO] Building war: D:\IntelliJ IDEA 2018.2.8\ideaProjects\MyFirstMaven\target\MyFirstMaven-1.0.0.RELEASE.war [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 24.101 s [INFO] Finished at: 2020-01-02T16:15:33+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:war (default-war) on project MyFirstMaven: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [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/MojoExecutionException Process finished with exit code 1
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.imooc</groupId> <artifactId>MyFirstMaven</artifactId> <version>1.0.0.RELEASE</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.47</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.1</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>
同学你好,这里同学完整的报错信息是否是--> Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project stuOriginManager: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
没有找到对应目录下的WEB-INF/web.xml内容。
出现这个问题的原因可能是,在此目录下找不到web.xml就抛出以上的异常,同学是否在对应webapp下有对应的web.xml文件
如果是这个问题,同学添加对应的web.xml文件,如果不是这个问题,还麻烦同学将具体的报错信息贴出,以及自己的配置文件贴出,比如同学自己的pom.xml文件,老师来复制测试一下。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星