上週我們的團隊決定從NetBeans遷移到Eclipse,因此我們開發了一些只能在Eclipse上運行的新插件。在Eclipse上運行maven項目
首先,項目開始使用我的maven插件pom <build>
標籤。但停止不起作用。在netbeans中,我使用exec-maven-plugin
來執行目標文件夾中的java -jar Project.jar
。下面是代碼:
<build>
<sourceDirectory>src/java</sourceDirectory>
<resources>
<resource>
<directory>src/cp</directory>
<targetPath>src/cp</targetPath>
</resource>
<resource>
<directory>src/rpt</directory>
<targetPath>src/rpt</targetPath>
</resource>
<resource>
<directory>src/sql</directory>
<targetPath>src/sql</targetPath>
</resource>
<resource>
<directory>etc</directory>
<targetPath>etc</targetPath>
</resource>
<resource>
<directory>www</directory>
<targetPath>www</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.4</version>
<configuration>
<connectionType>connection</connectionType>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>setVersion</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sh</executable>
<arguments>
<argument>./etc/changeVersion.sh</argument>
</arguments>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</execution>
<execution>
<id>debugJar</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cd target/</executable>
<executable>java</executable>
<arguments>
<argument>-Xdebug</argument>
<argument>-Xnoagent</argument>
<argument>-Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</argument>
<argument>-jar </argument>
<argument>${project.artifactId}-${project.version}.jar</argument>
</arguments>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</execution>
<execution>
<id>runJar</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cd target/</executable>
<executable>java</executable>
<arguments>
<argument>-jar </argument>
<argument>${project.artifactId}-${project.version}.jar</argument>
</arguments>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</execution></executions>
</plugin><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Project-Name>${project.artifactId}</Project-Name>
<!-- Uncomment if you want to make changes and/or debug in Entuito-->
<!--<Class-Path>${local.OurFramework.dir}${OurFramework.jar}</Class-Path>-->
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<mainClass>${project.groupId}.Mammut</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<extensions>
<!-- Enabling the use of SSH -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.10</version>
</extension>
</extensions>
在NetBeans中,當我們用這個建項目有用於調試和運行使用NetBeans控制按鈕沒有問題。但在Eclipse中,項目運行和停止按鈕不會停止項目。進程java -jar Project.jar
仍在運行,我們必須使用htop或其他方法來殺死它。 複製所有庫和包裝的原因是慢進程並且使用了許多讀/寫操作,我們希望使用Java應用程序運行來運行和調試項目,並且不需要爲每個項目重建整個項目微小的變化。但這個問題也發生在這裏。每個項目都有依賴關係,這是我們的java框架,所有的框架資源文件都在jar包內(一些conf.xml文件,圖像等)。在大多數情況下,當需要修改我們的項目來改變我們的項目在一個工作區中打開。 Netbeans和Eclipse會自動檢測依賴位置,並將其從.m2文件夾更改爲此刻打開的工作區項目。
這裏的問題是,當我使用maven clean install
作爲框架,然後運行使用JavaApp的主項目時,項目不運行,導致無法從框架中找到資源文件。此時,如果我從工作區關閉frameWork並運行主項目Eclipse,則將依賴路徑更改爲.m2文件夾,一切正常,但這是非常緩慢的過程,並且使調試變得不可能。 任何人都可以共享一個可以幫助我解決問題或任何建議的pom構建,並且如果我的方法錯誤,可以指導「如何」正確地完成它。
請注意,您可以在Eclipse和Netbeans之間切換Maven項目 –
我不是100%確定我的Netbeans conf使用maven-exec-plugin運行項目是運行它的最佳方式。 如果不打包和複製java代碼中每一個改變的所有依賴關係,那將是非常好的。如果每次通過java -jar命令運行它,這都是不可能的。 –