Java 通过Eclipse的Maven Web项目

Java 通过Eclipse的Maven Web项目,java,eclipse,maven,Java,Eclipse,Maven,我在Eclipse中创建了一个DynamicWebProject,然后按下RUN按钮。浏览器窗口在生成项目后打开。这正是我想要的。现在,我创建了一个带有webapps archtype的Maven项目。有一个默认的index.jsp文件。现在我按下运行按钮。什么也没发生。然后我创建了一个运行配置并添加了Tomcat服务器。现在服务器启动了,但浏览器没有启动,我的应用也没有部署。我应该做什么样的更改,使其与动态web项目案例相似?没有mvn部署或打包到WAR archieve和extract中。老

我在Eclipse中创建了一个DynamicWebProject,然后按下RUN按钮。浏览器窗口在生成项目后打开。这正是我想要的。现在,我创建了一个带有webapps archtype的Maven项目。有一个默认的index.jsp文件。现在我按下运行按钮。什么也没发生。然后我创建了一个运行配置并添加了Tomcat服务器。现在服务器启动了,但浏览器没有启动,我的应用也没有部署。我应该做什么样的更改,使其与动态web项目案例相似?没有mvn部署或打包到WAR archieve和extract中。

老实说,我不明白您想做什么(或做了什么),但是,如果您甚至提到maven和eclipse,那么您应该使用m2eclipse-t,然后您应该深入研究maven文档-有很多示例,其中可能有一个

如何通过maven设置tomcat。对于开发,我建议切换到jetty-它更方便、更易于部署(实际上它是自动部署的):

它在pom.xml中的外观的一小部分

<!-- Normally, testing a web application involves compiling Java sources, 
                    creating a WAR and deploying it to a web container. Using the Jetty Plugin 
                    enables you to quickly test your web application by skipping the last two 
                    steps. By default the Jetty Plugin scans target/classes for any changes in 
                    your Java sources and src/main/webapp for changes to your web sources. The 
                    Jetty Plugin will automatically reload the modified classes and web sources -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>${jetty.port}</port>
                            <maxIdleTime>60000</maxIdleTime>
                            <Host>localhost</Host>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>

org.mortbay.jetty
maven jetty插件
${jetty.version}
10
${jetty.port}
60000
本地服务器
我相信类似的事情也可以通过tomcat实现


我认为,你要问的其他问题太模糊了,无法回答,所以请说得具体一点。

老实说,我不明白你想做什么(或做了什么),但是,如果你提到maven和eclipse,然后您应该使用m2eclipse-t,然后您应该深入研究maven文档——这里有大量的示例,其中可能有一个

如何通过maven设置tomcat。对于开发,我建议切换到jetty-它更方便、更易于部署(实际上它是自动部署的):

它在pom.xml中的外观的一小部分

<!-- Normally, testing a web application involves compiling Java sources, 
                    creating a WAR and deploying it to a web container. Using the Jetty Plugin 
                    enables you to quickly test your web application by skipping the last two 
                    steps. By default the Jetty Plugin scans target/classes for any changes in 
                    your Java sources and src/main/webapp for changes to your web sources. The 
                    Jetty Plugin will automatically reload the modified classes and web sources -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${jetty.version}</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>${jetty.port}</port>
                            <maxIdleTime>60000</maxIdleTime>
                            <Host>localhost</Host>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>

org.mortbay.jetty
maven jetty插件
${jetty.version}
10
${jetty.port}
60000
本地服务器
我相信类似的事情也可以通过tomcat实现


我认为,您所问的其他问题太模糊,无法回答,因此请更具体一些。

我试图总结在eclipse内的tomcat服务器上部署一个简单的maven web应用程序所需的步骤(使用eclipse indigo进行测试)

1.)获取eclipse
2.)通过eclipse市场安装两个插件(Maven integration for eclipse和Maven integration for eclipse WTP,也称为m2eclipse和m2eclipse extras)
3.)下载tomcat服务器
4.)打开Eclipse-Server视图并添加tomcat服务器
5.)创建一个新的maven项目(使用archtype web app)
6.)使用以下代码增强pom:

<dependencies>
    <!-- ... something like junit could already be in dependencies -->
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
           <scope>provided</scope>
    </dependency>
    <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
    </dependency>
</dependencies>

javax.servlet

按照上述步骤,maven webapp应该自动部署到tomcat。不需要“mvn部署”或打包到WAR就可以手动进入tomcat


双击服务器配置打开服务器属性。您可以在那里找到webapps的部署路径。

我试图总结在eclipse中的tomcat服务器上部署简单maven web app所需的步骤(使用eclipse indigo进行测试)

1.)获取eclipse
2.)通过eclipse市场安装两个插件(Maven integration for eclipse和Maven integration for eclipse WTP,也称为m2eclipse和m2eclipse extras)
3.)下载tomcat服务器
4.)打开Eclipse-Server视图并添加tomcat服务器
5.)创建一个新的maven项目(使用archtype web app)
6.)使用以下代码增强pom:

<dependencies>
    <!-- ... something like junit could already be in dependencies -->
    <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
           <scope>provided</scope>
    </dependency>
    <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
    </dependency>
</dependencies>

javax.servlet

按照上述步骤,maven webapp应该自动部署到tomcat。不需要“mvn部署”或打包到WAR就可以手动进入tomcat


双击服务器配置打开服务器属性。您可以在那里找到webapps的部署路径。

使用Eclipse Run Jetty Run运行您的项目,只需单击一次,无需任何配置

参考文献

使用Eclipse Run Jetty Run运行您的项目,只需单击一次,无需任何配置

参考文献

您安装了m2eclipse插件吗?您安装了m2eclipse插件吗?我按照上述步骤操作,但我的应用程序没有部署。您有什么问题?您是否也安装了maven extras(EclipseWTP的maven集成)?你的tomcat是如何集成的?(通过eclipse或separated)如果没有更多信息,这对任何人来说都很难解决。我遵循了上述步骤,但我的应用程序没有得到部署。您有什么问题?您是否也安装了maven extras(EclipseWTP的maven集成)?你的tomcat是如何集成的?(通过eclipse或separated)如果没有更多信息,这对任何人来说都很难解决。