我正在寻找如何在 Eclipse 和 Maven 中使用 Tomcat 的最佳方式。
我有一些开发 Java EE 应用程序的经验,并且我期望在使用 Maven 时会出现类似的行为。
我的要求很简单:
- 简单的应用程序构建
 - 易于部署
 - 如果可能,热插拔
 
我不知道 Tomcat + Eclipse 的详细工作原理,所以我假设 Maven 命令
mvn eclipse:eclipse -Dwtpversion=2.0
正确设置了所有内容,但我怀疑它运行不正常(或至少按预期运行)。
当项目(我们称之为测试)在 Maven 中构建时,结果在${project}/target/test文件夹中。但在我看来,Tomcat 的类来自不同的文件夹(${project}/target/classes?)。恕我直言,这是错误的(如果我错了,请纠正我),但 maven 可以在构建类之前执行其他操作 - 代码生成、资源过滤、AOP 编织等。
有一些建议如何使用吗?因为mvn clean install从命令行执行并将结果部署到 Tomcat 在我看来不像 IDE(集成开发环境)。是否可以指示 maven eclipse 插件正确设置它?
我也尝试使用mvn tomcat:run,但在这里我完全迷路了,我遇到了我不明白的错误
java.lang.NoSuchMethodError: org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass
而且我不知道为什么在使用 Tomcat 6 的服务器运行时它不能在 Eclipse 中正常工作。
mvn install当我保存课程时,是否可以指示 Eclipse 执行 let say ?会比吗?这是否足够快(仅重建改变的东西+依赖项,就像我习惯于从标准 JSE 项目中那样)?
其实我正在使用
- 行家3.0.4
 - 爪哇 1.6
 - 日食 4.2.1 ( STS 3.2.0.M2)
 - tomcat 6(我们目前正在为 Tomcat 6 开发,但我猜 7 也是一样的)
 
编辑
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>
        <!-- WSDL -> Java (start) -->
        <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>
        <!-- WSDL -> Java (end) -->
        <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 used to replace variables from in property files -->
                <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>
            <!-- add src/main/generated for maven -->
            <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>
            <!-- WSDL -> Java (start) -->
            <plugin>
                <!-- !!! READ !!! -->
                <!-- mvn cxf-codegen-plugin:wsdl2java NOT working, comment phase and run "mvn clean install -DskipTests") -->
                <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>
                <!-- resources in UTF-8 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.5</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
                <!-- JUnit -->
                <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>