I am looking for the best way to use Tomcat in Eclipse with Maven.
I have experience developing Java EE applications, and I expect similar behavior when using Maven.
My requirements are simple:
- easy application creation
- easy deployment
- hot swap if possible
I donβt know how Tomcat + Eclipse works in detail, so I assumed that the Maven team
mvn eclipse:eclipse -Dwtpversion=2.0
configures everything correctly, but I have a suspicion that it does not work well (or at least as expected).
When a project (let it call a test) is built into maven, the result is in the ${project}/target/test folder. But it seems to me that the classes for Tomcat are different folders ( ${project}/target/classes ?). This is a wrong IMHO (correct me if I am mistaken), but maven can perform other actions before creating classes - code generation, resource filtering, AOP weaving, etc.
Are there any recommendations for its use? Since running mvn clean install from the command line and deploying the result to Tomcat doesn't sound like an IDE (Integrated development environment) to me. Can I configure the maven eclipse plugin for proper configuration?
I also tried using mvn tomcat:run , but here I am completely lost, I get errors that I do not understand. fe
java.lang.NoSuchMethodError: org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass
and I have no idea why it does not work when using server runtime for tomcat 6 works fine from eclipse.
Can I instruct Eclipse to run let say mvn install when I save the class? Will it work than? Will it be fast enough (restoring only changed things + dependencies, since I'm used to standard JSE projects)?
I actually use
- maven 3.0.4
- java 1.6
- eclipse 4.2.1 ( STS 3.2.0.M2)
- tomcat 6 (we are currently developing Tomcat 6, but I think it is the same for 7)
change
some relevant parts from pom.xml
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>war</packaging> <properties> <spring.version>3.1.1.RELEASE</spring.version> <cxf.version>2.7.3</cxf.version> <cxf-codegen-plugin.version>2.6.1</cxf-codegen-plugin.version> <cxf.sourceRoot>src/main/generated</cxf.sourceRoot> <junit.version>4.11</junit.version> <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format> <project.build.date>${maven.build.timestamp}</project.build.date> </properties> <dependencies> ... </dependencies> <build> <resources> <resource> <filtering>true</filtering> <directory>${basedir}/src/main/java</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> <resource> <filtering>false</filtering> <directory>${basedir}/src/main/resources</directory> </resource> </resources> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/generated</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>${cxf-codegen-plugin.version}</version> <executions> ... </executions> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <version>2.5.1</version> <inherited>true</inherited> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <version>2.1.1</version> <artifactId>maven-war-plugin</artifactId> <configuration> <warName>test</warName> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.8</version> <configuration> <redirectTestOutputToFile>true</redirectTestOutputToFile> </configuration> </plugin> <plugin> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <wtpversion>1.5</wtpversion> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
java eclipse maven tomcat
Betlista
source share