使用eclipse与maven插件,我应该如何设置我的构建,所以它部署到tomcat? [英] Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?

查看:179
本文介绍了使用eclipse与maven插件,我应该如何设置我的构建,所以它部署到tomcat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我不知道我是否必须在1或更高版本中执行此操作2步,但我想编译我的spring mvc(3)应用程序并部署到我的本地tomcat。



现在我刚刚将RunAs - > Maven构建映射到'编译'目标类型。



我很新,不知道如何设置构建和部署。



我的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 /行家-v4_0_0.xsd>
< modelVersion> 4.0.0< / modelVersion>
< groupId> com.example< / groupId>
< artifactId> springmvc2< / artifactId>
< packaging> war< / packaging>
< version> 0.0.1-SNAPSHOT< / version>
< name> springmvc2 Maven Webapp< / name>
< url> http://maven.apache.org< / url>
<依赖关系>
<依赖关系>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 3.8.1< / version>
< scope> test< / scope>

< / dependency>
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> 3.0.0.RELEASE< / version>
< / dependency>
<依赖关系>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 3.3.2.GA< / version>
< / dependency>
<依赖关系>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-annotations< / artifactId>
< version> 3.4.0.GA< / version>
< / dependency>
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< version> 3.0.0.RELEASE< / version>
< / dependency>
<依赖关系>
< groupId> org.mod4j.org.apache.commons< / groupId>
< artifactId> logging< / artifactId>
< version> 1.0.4< / version>
< / dependency>
< / dependencies>
< build>
< finalName> springmvc2< / finalName>
< filters>
< / filters>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< configuration>

< source> 1.6< / source>
< target> 1.6< / target>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>


解决方案

Eclipse内部



假设您已经安装了WTP(Web Tools Project)(它是Java EE开发人员发行版的Eclipse IDE的一部分),并且安装了emMaven Integration for WTP这是m2eclipse的可选模块,您必须明确指出),那么您的弹簧项目应被识别为动态Web项目,并可在服务器上运行。在这种情况下,只需在项目中右键单击,转到运行方式>在服务器上运行,选择手动定义新服务器并使用向导添加您当地的Tomcat。



Eclipse之外



您可以简单地执行:

  mvn tomcat:run 

这将使用嵌入式Tomcat服务器将当前项目作为动态Web应用程序运行。



如果您想要的是真正部署到您的本地Tomcat,那么看一下 tomcat:deploy 目标。



当然,您可以始终从Eclipse运行这些目标,但我建议您在此使用IDE支持(即WTP)。如果要在调试模式等运行Tomcat,这将更容易。


Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?

I'm not sure if I have to do this in 1 or 2 steps, but I want to compile my spring mvc (3) application and deploy to my local tomcat.

Right now I just mapped the RunAs -> Maven build to a 'compile' goal type.

I'm very new to do this so not sure how to setup build and deploy.

My pom.xml is:

<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>com.example</groupId>
 <artifactId>springmvc2</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <name>springmvc2 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.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>3.0.0.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>3.3.2.GA</version>
  </dependency>
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-annotations</artifactId>
   <version>3.4.0.GA</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>3.0.0.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>org.mod4j.org.apache.commons</groupId>
   <artifactId>logging</artifactId>
   <version>1.0.4</version>
  </dependency>
 </dependencies>
 <build>
  <finalName>springmvc2</finalName>
  <filters>
  </filters>
  <plugins>
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>   
    <configuration>

     <source>1.6</source>
     <target>1.6</target>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

解决方案

Inside Eclipse

Assuming you have the WTP (Web Tools Project) installed (which is part of the Eclipse IDE for Java EE developers distro) and you have the "Maven Integration for WTP" installed (which is an optional module of m2eclipse, you have to intall it explicitly), then your spring project should be recognized as a dynamic web project and runnable on a Server. In that case, just right-click on your project, go to Run As > Run on Server, select Manually define a new server and use the wizard to add your local Tomcat.

Outside Eclipse

You can simply execute:

mvn tomcat:run 

This will run the current project as a dynamic web application using an embedded Tomcat server.

If what you want is really to deploy to your local Tomcat, then have a look at the tomcat:deploy goal.

Of course, you can always run these goals from Eclipse but I'd recommend to use the IDE support here (i.e. the WTP). This will be easier if you want to run your Tomcat in debug mode, etc.

这篇关于使用eclipse与maven插件,我应该如何设置我的构建,所以它部署到tomcat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆