简体   繁体   English

在Eclipse的tomcat中运行Java Servlet Maven Web应用程序

[英]Run a java servlet maven webapp in tomcat in eclipse

I use Eclipse Mars. 我使用Eclipse Mars。 I have a server runtime configured in eclipse for Tomcat8. 我在Eclipse中为Tomcat8配置了服务器运行时。

I created a maven webapp project with a very simple servlet that only does a sysout() statement when the (overriden) init runs. 我用一个非常简单的servlet创建了一个maven webapp项目,该servlet仅在(重写)init运行时才执行sysout()语句。

I'm trying to run the webapp in tomcat, hoping to see the sysout statement when the servlet is initialized. 我正在尝试在tomcat中运行webapp,希望在初始化servlet时看到sysout语句。 However, I'm under the impression none of my java classes are actually being compiled/build and put under the web-inf folder because tomcat starts fine, but I see no sysouts. 但是,我给我的印象是,我的所有Java类实际上都没有被编译/构建,也没有放置在web-inf文件夹下,因为tomcat可以很好地启动,但是我看不到任何sysouts。

When I go to localhost:8080/HelloWorld/ I expect my servlet's doGet() method to run (I also put a sysout in that method), but instead I get a 404. 当我转到localhost:8080 / HelloWorld /时,我希望我的servlet的doGet()方法能够运行(我也在该方法中放入了sysout),但是却得到了404。

Here's my project layout (standard maven): 这是我的项目布局(标准Maven): 在此处输入图片说明

And my pom (I removed the irrelevant parts). 和我的pom(我删除了不相关的部分)。 I believe the build plugins are not executed when I start my tomcat. 我相信启动tomcat时不会执行构建插件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ...">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>HelloWorld</name>

    <properties>
        ...
    </properties>

    <dependencies>
        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>HelloWorld</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

And my web.xml 还有我的web.xml 在此处输入图片说明

Here's the init method from my servlet: 这是我的servlet的init方法:

@Override
public void init(ServletConfig servletconfig) throws ServletException
{
    System.out.println("sysout servlet");
}

And of course I added the project to my tomcat config: 当然,我将项目添加到了我的tomcat配置中:

在此处输入图片说明

[ http://bigleap.co.in/corp/2013/06/running-maven-project-within-eclipse-on-tomcat/][1] . [ http://bigleap.co.in/corp/2013/06/running-maven-project-within-eclipse-on-tomcat/][1] you exactly need to set goals to compile and run maven project in eclipse tomact. 您确实需要设定目标以在Eclipse Eclipse中编译和运行Maven项目。 two goals clean:instal and tomact7:run. 清洁,安装和tomact7:run这两个目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM