我通过maven 3.1.1创建了一个简单的webapp。我只想开发一个简单的servlet。在完成一个干净的安装之后,我期望目标/WEB/中的servlet的类文件。但只有复制的源文件。
我做错什么了?
我还没有得出任何结论:
-系统信息
- 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>de.mypage</groupId>
<artifactId>ThirdServlet</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ThirdServlet Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>servlet-api</artifactId>
<version>6.0.37</version>
</dependency>
</dependencies>
<build>
<finalName>ThirdServlet</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
- File-Structure
-我的Servlet
some imports
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public MyServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<body>");
pw.println("<h2>");
pw.println("If you can read this the servlet is running...");
pw.println("</h2>");
pw.println("</body>");
pw.println("</html>");
pw.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}}
发布于 2013-12-26 14:23:59
您的Java代码应该在src/main/java中而不是在src/main/resources中。编译了Java代码,并复制了资源。这些不是包,而是Maven定义的文件夹。
修复此问题后,可能需要打包war和/或使用Maven tomcat插件运行war。目标‘`install’意味着部署到本地Maven存储库。
在Eclipse中:

在文件系统上:

发布于 2013-12-27 17:14:15
我为我找到了一个可行的解决方案。我刚刚在eclipse中向现有的构建路径添加了一个新路径。
我认为这不是一个完美的方法--尤其是从maven的角度。但它起作用了,我会深入研究maven架构.
https://stackoverflow.com/questions/20785484
复制相似问题