maven / eclipse / java的新手
1)用eclipse创建了一个新的动态web项目。
2)创建了2个servlet和2个jsp(遵循本教程:http://blog.piraya.nl/2012/11/submitting-pdf-forms-in-java.html)。
3)将pom.xml文件(从教程中复制)添加到项目的根目录中。
4)对项目进行了规范化(Project-> configure->转换为maven项目)
5)以maven install的身份运行
6)在服务器上运行
这是maven安装输出
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building PDFForms 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ PDFForms ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\eclipse-workspace\PDFForms\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ PDFForms ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ PDFForms ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\eclipse-workspace\PDFForms\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ PDFForms ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ PDFForms ---
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ PDFForms ---
[INFO] Packaging webapp
[INFO] Assembling webapp [PDFForms] in [D:\eclipse-workspace\PDFForms\target\PDFForms-1.0]
[INFO] Processing war project
[INFO] Webapp assembled in [52 msecs]
[INFO] Building war: D:\eclipse-workspace\PDFForms\target\PDFForms-1.0.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.469 s
[INFO] Finished at: 2018-04-05T08:31:02+02:00
[INFO] Final Memory: 12M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project PDFForms: 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
这是服务器输出上的运行
INFORMAZIONI: Server startup in 9395 ms
apr 05, 2018 8:18:48 AM org.apache.catalina.core.ApplicationContext log
INFORMAZIONI: Marking servlet [PDFFormServlet] as unavailable
apr 05, 2018 8:18:48 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Allocate exception for servlet [PDFFormServlet]
java.lang.ClassNotFoundException: nl.piraya.blog.PDFServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1041)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:770)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
这是从教程中复制的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.piraya.blog</groupId>
<artifactId>PDFForms</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>PDFForms</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
</plugin>
</plugins>
</build>
</project>
这是web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>PDFForms</display-name>
<!-- This servlet generates a PDF form on the fly. -->
<servlet>
<servlet-name>PDFFormServlet</servlet-name>
<servlet-class>PDFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PDFFormServlet</servlet-name>
<url-pattern>/dynamic.pdf</url-pattern>
</servlet-mapping>
<!-- This PDF accepts submitted FDF data. -->
<servlet>
<servlet-name>FDFServlet</servlet-name>
<servlet-class>nl.piraya.blog.FDFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FDFServlet</servlet-name>
<url-pattern>/fdf</url-pattern>
</servlet-mapping>
<!-- Make sure the index.jsp file is opened when people access the application. -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
答案 0 :(得分:0)
您的项目中是否存在web.xml文件?
如果servlet版本小于3.0,则必须使用WEB-INF \ web.xml 对于大于或等于3.0的版本,没有web.xml并添加以下依赖项
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
尝试在pom.xml文件中添加此依赖项。