我在Eclipse中创建了一个DynamicWebProject,然后按下了RUN按钮。构建项目后打开浏览器窗口。这完全符合我的要求。现在我用webapps archtype创建一个Maven项目。有一个默认的index.jsp文件。现在我按下运行按钮。没啥事儿。然后我创建了一个运行配置并添加了Tomcat服务器。现在服务器启动但浏览器无法启动,我的应用程序也未部署。我应该做些什么改变,以便它会像动态网络项目一样?没有mvn部署或打包到WAR archieve和extract。
答案 0 :(得分:2)
我尝试总结在eclipse中在tomcat服务器上部署简单的maven Web应用程序所需的步骤(使用eclipse indigo进行测试)。
1。)得到日食
2.)通过eclipse市场安装两个插件(用于eclipse的Maven集成和用于eclipse WTP的Maven集成,也称为m2eclipse和m2eclipse附加组件)
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>
7。)右键单击tomcat服务器(eclipse - 服务器视图)并添加新的maven项目
8.)启动tomcat
9.)打开浏览器并输入http://localhost:8080/APPNAME
按照上述步骤,maven webapp应自动部署到tomcat。无需'mvn deploy'或打包到WAR手动下载到tomcat。
双击服务器配置将打开服务器属性。在那里,您可以找到webapps的部署路径。
答案 1 :(得分:1)
老实说,我不明白你想要做什么(或做过),但是,如果你甚至提到maven和eclipse,那么你应该使用m2eclipse - t然后你应该深入研究maven文档 - 有很多例子,其中一个可能 http://mojo.codehaus.org/tomcat-maven-plugin/run-mojo.html
如何通过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>
我确信使用tomcat可以实现类似的功能。
我想,你要问的其他事情太模糊了,无法回答,所以请更具体一点。
答案 2 :(得分:0)
使用Eclipse Run-Jetty-Run运行您的项目,只需单击一下即可完成任何配置!