[英]How do I fix maven exec:java which is mangling jar file names?
我正在Windows上使用JOGL開發應用程序。 到目前為止,我一直在使用Eclipse,但是我已經開始編寫相應的Maven POM文件,以便可以自動進行構建和打包步驟。
JOGL在Maven中未得到積極維護,因此我編寫了一個小腳本,該腳本通過install:install-file將jar導入我的本地存儲庫:
set JOGL_VER=2.0
set JOGL_HOME=./jogl
set JOGL_LIB=%JOGL_HOME%/jar
set MVN_INSTALL=call mvn install:install-file
%MVN_INSTALL% -DgroupId=org.jogamp.gluegen -Dfile=%JOGL_LIB%/gluegen-rt-natives-windows-i586.jar \
-DartifactId=gluegen-rt-natives-windows-i586 -Dversion=%JOGL_VER% -Dpackaging=jar
%MVN_INSTALL% -DgroupId=org.jogamp.gluegen -Dfile=%JOGL_LIB%/gluegen.jar \
-DartifactId=gluegen -Dversion=%JOGL_VER% -Dpackaging=jar
%MVN_INSTALL% -DgroupId=org.jogamp.jogl -Dfile=%JOGL_LIB%/jogl-all-natives-windows-i586.jar \
-DartifactId=jogl-all-natives-windows-i586 -Dversion=%JOGL_VER% -Dpackaging=jar
%MVN_INSTALL% -DgroupId=org.jogamp.jogl -Dfile=%JOGL_LIB%/jogl-all.jar
-DartifactId=jogl-all -Dversion=%JOGL_VER% -Dpackaging=jar
這導致我的回購中有以下文件
.m2\repository\org\jogamp\gluegen\gluegen\2.0\gluegen-2.0.jar
.m2\repository\org\jogamp\gluegen\gluegen\2.0\gluegen-2.0.pom
.m2\repository\org\jogamp\gluegen\gluegen-rt-natives-windows-i586\2.0\gluegen-rt-natives-windows-i586-2.0.jar
.m2\repository\org\jogamp\gluegen\gluegen-rt-natives-windows-i586\2.0\gluegen-rt-natives-windows-i586-2.0.pom
.m2\repository\org\jogamp\jogl\jogl-all\2.0\jogl-all-2.0.jar
.m2\repository\org\jogamp\jogl\jogl-all\2.0\jogl-all-2.0.pom
.m2\repository\org\jogamp\jogl\jogl-all-natives-windows-i586\2.0\jogl-all-natives-windows-i586-2.0.jar
.m2\repository\org\jogamp\jogl\jogl-all-natives-windows-i586\2.0\jogl-all-natives-windows-i586-2.0.pom
請注意,由於我指定了2.0,因此文件帶有2.0后綴,例如,glugengen-rt-natives-windows-i586-2.0.jar。
但是現在我想使用exec:java命令在構建后運行應用程序,以確保其正常運行,即
mvn exec:java
所以我將exec-maven-plugin添加到我的pom.xml中
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.testapp.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
並且我還將依賴項添加到JOGL。 並不是說本機二進制文件是作用域范圍內的運行時,因為我在編譯時不需要它們:
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-natives-windows-i586</artifactId>
<version>2.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-natives-windows-i586</artifactId>
<version>2.0</version>
<scope>runtime</scope>
</dependency>
但是當我運行它時,出現以下錯誤
Catched FileNotFoundException: C:\Users\xxx\.m2\repository\org\jogamp\gluegen\gluegen\2.0\gluegen-2.0-natives-windows-i586.jar (
The system cannot find the file specified), while TempJarCache.bootstrapNativeLib() of jar:file:/C:/Users/xxx/.m2/repository/org
/jogamp/gluegen/gluegen/2.0/gluegen-2.0-natives-windows-i586.jar!/ (file:/C:/Users/xxx/.m2/repository/org/jogamp/gluegen/gluegen
/2.0/ + gluegen-2.0-natives-windows-i586.jar)
[WARNING]
因此,問題很簡單。 我通過install:install-file安裝了jar,並且在工件ID后面附加了版本2.0,例如gelgen-rt-natives-windows-i586- 2.0 .jar,但是exec:java期望jar被稱為gelengen- 2.0- natives-windows-i586.jar。
由於項目已生成,因此我必須假定編譯階段正在使用期望的文件名正確查找jar文件,但是exec卻沒有。
為什么將版本號轉儲在工件ID的中間,我如何使其正常工作? 工件ID是根據約定命名的,所以我不明白為什么會這樣拆分。
Exec:java與您的問題無關。
JOGL本身具有某種復雜的內部機制,用於通過JNI管理本機代碼,並且該機制對文件名進行了假設,這些文件名與Maven規則在存儲庫中命名文件不兼容。
您將必須使用maven-assembly-plugin將依賴項復制到具有JOGL所需名稱和形狀的樹,然后從那里執行,或者找到一種方法來重新配置JOGL以容許Maven命名約定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.