Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7)

来源:互联网 发布:c指针的编程题 编辑:程序博客网 时间:2024/06/17 14:08

1.Install maven plugin(The picture following showed for you means you maven plugin "Maven Integration for Eclipse" was already installed)

Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客

 

2. Add tomcat 7 server to eclipse IDE(On picture you can find tomcat version information.)

Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 

 Change publishing option and Server Locations option.

Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客

 3. Create a maven project, and config it  as a jsf project.

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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>

 <groupId>com.demo</groupId> <artifactId>test1</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>Test1</name>

 <properties>  <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  <project.build.finalName>${project.name}</project.build.finalName>  <dependency.scope>compile</dependency.scope> </properties>

 <dependencies>  <dependency>   <groupId>javax</groupId>   <artifactId>javaee-web-api</artifactId>   <version>6.0</version>   <scope>provided</scope>  </dependency>  <dependency>   <groupId>com.sun.faces</groupId>   <artifactId>jsf-api</artifactId>   <version>2.1.11</version>   <scope>compile</scope>  </dependency>  <dependency>   <groupId>com.sun.faces</groupId>   <artifactId>jsf-impl</artifactId>   <version>2.1.11</version>   <scope>compile</scope>  </dependency>  <!-- for JSF 2.x -->  <dependency>   <groupId>javax.servlet</groupId>   <artifactId>jstl</artifactId>   <version>1.2</version>  </dependency>  <dependency>   <groupId>javax.servlet</groupId>   <artifactId>servlet-api</artifactId>   <version>2.5</version>   <scope>provided</scope>  </dependency>  <dependency>   <groupId>javax.el</groupId>   <artifactId>el-api</artifactId>   <version>2.2</version>  </dependency>

  <dependency>   <groupId>org.slf4j</groupId>   <artifactId>slf4j-api</artifactId>   <version>1.6.1</version>  </dependency>

  <dependency>   <groupId>org.slf4j</groupId>   <artifactId>slf4j-log4j12</artifactId>   <version>1.6.1</version>  </dependency>

  <dependency>   <groupId>log4j</groupId>   <artifactId>log4j</artifactId>   <version>1.2.16</version>   <exclusions>    <exclusion>     <groupId>javax.mail</groupId>     <artifactId>mail</artifactId>    </exclusion>    <exclusion>     <groupId>javax.jms</groupId>     <artifactId>jms</artifactId>    </exclusion>    <exclusion>     <groupId>com.sun.jdmk</groupId>     <artifactId>jmxtools</artifactId>    </exclusion>    <exclusion>     <groupId>com.sun.jmx</groupId>     <artifactId>jmxri</artifactId>    </exclusion>   </exclusions>  </dependency> </dependencies>

 <build>  <finalName>${project.name}</finalName>  <defaultGoal>install</defaultGoal>

  <resources>   <resource>    <targetPath></targetPath>    <directory>src/main/resources</directory>    <filtering>true</filtering>   </resource>  </resources>

  <plugins>

   <plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-compiler-plugin</artifactId>    <version>2.3.2</version>    <configuration>     <source>1.7</source>     <target>1.7</target>     <encoding>${project.build.sourceEncoding}</encoding>     <compilerArguments>      <endorseddirs>${endorsed.dir}</endorseddirs>     </compilerArguments>    </configuration>   </plugin>   <plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-war-plugin</artifactId>    <version>2.1.1</version>    <configuration>     <webappDirectory>target/${project.name}</webappDirectory>     <warSourceDirectory>src/main/webapp</warSourceDirectory>     <failOnMissingWebXml>false</failOnMissingWebXml>    </configuration>   </plugin>   <plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-dependency-plugin</artifactId>    <version>2.1</version>    <executions>     <execution>      <phase>validate</phase>      <goals>       <goal>copy</goal>      </goals>      <configuration>       <outputDirectory>${endorsed.dir}</outputDirectory>       <silent>true</silent>       <artifactItems>        <artifactItem>         <groupId>javax</groupId>         <artifactId>javaee-endorsed-api</artifactId>         <version>6.0</version>         <type>jar</type>        </artifactItem>       </artifactItems>      </configuration>     </execution>    </executions>   </plugin>  </plugins>  <pluginManagement>   <plugins>    <!--This plugin's configuration is used to store Eclipse m2e settings      only. It has no influence on the Maven build itself. -->    <plugin>     <groupId>org.eclipse.m2e</groupId>     <artifactId>lifecycle-mapping</artifactId>     <version>1.0.0</version>     <configuration>      <lifecycleMappingMetadata>       <pluginExecutions>        <pluginExecution>         <pluginExecutionFilter>          <groupId>           org.apache.maven.plugins          </groupId>          <artifactId>           maven-dependency-plugin          </artifactId>          <versionRange>           [2.1,)          </versionRange>          <goals>           <goal>copy</goal>           <goal>            copy-dependencies           </goal>          </goals>         </pluginExecutionFilter>         <action>          <ignore></ignore>         </action>        </pluginExecution>       </pluginExecutions>      </lifecycleMappingMetadata>     </configuration>    </plugin>   </plugins>  </pluginManagement> </build>

</project>

project struture maybe like this:
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
Config "Run Configurations" and run it(Project menu --> Run as --> Maven build)
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
Config source output directory to "target/Test1/WEB-INF/classes"(If can't find the folder, refresh project)
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
Config tomcat 7 to deploy the project, open server.xml file in Servers project(When you added a server this project is existed)
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
Add this line to deploy project(nested in Host XML element):
<Context docBase="D:\projects\Test1\target\Test1" path="/Test" reloadable="false"></Context>\
"D:\projects\Test1" is project base path, "target\Test1" will be generated after maven build project.
4. Debugging
Make a breakpoint in your java code(In my demo project, I maked one in jsf managed bean, and triggle it by submitting a jsf action.)
 
Start tomcat server in debug mode.
 
Open your browser and open url "http://localhost:8080/Test/index.jsf", then click the button and submit an action:
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
The IDE find the breakpoint but not found the source code, then click "edit source lookup path" button to add project source path:
 
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
 
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
 
OK, then go to breakpoint
Eclipse(4.2) maven(3.0.4--m2e) integrate with tomcat 7 (win7) - yyq2007aa - 流星永恒的博客
 
If you delete a line of method "say", you don't need redepoly project util it taking effect.

That's it.
0 0
原创粉丝点击