我正在尋找如何在Eclipse和Maven中使用Tomcat的最佳方式。如何在Eclipse中正確使用Tomcat的maven
我有一些開發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
但在這裏我完全失去了,我得到的錯誤我不明白f.e.
java.lang.NoSuchMethodError: org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass
我不知道爲什麼它不工作,而使用tomcat的服務器運行時6在eclipse中工作正常。
當我保存課程時,是否可以指示Eclipse執行比如說mvn install
?它會起作用嗎?這是否足夠快(重建只改變了東西+依賴,因爲我習慣於從標準JSE項目中)?
其實我使用
- 行家3.0.4
- 的Java 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>
請問您可以發佈您的pom嗎?包裝是否打仗? – guerda 2013-03-04 12:23:44
您需要服務器視圖,右鍵單擊並添加服務器並選擇Tomcat,然後才能在Eclipse中部署您的Web項目。這也支持熱插拔。 – 2013-03-04 12:26:50
@furtelwart:我的實際pom.xml是要大的發佈它在這裏(很多東西是不相關的這個問題),但回答你的評論是,我有'戰爭 '在我的朋友,也' maven-war-plugin '配置好了,我的問題不是它沒有工作,而只是太複雜了... @Bob Flannigon:這是正確的,但它需要錯誤的文件夾($ {project}/target/classes ),因爲我寫在我的問題... –
Betlista
2013-03-04 12:31:12