简体   繁体   English

如何修复损坏jar文件名的maven exec:java?

[英]How do I fix maven exec:java which is mangling jar file names?

I'm developing an app using JOGL on Windows. 我正在Windows上使用JOGL开发应用程序。 I've been using Eclipse thus far but I have started writing a corresponding Maven POM file so I can automatic the build and packaging steps. 到目前为止,我一直在使用Eclipse,但是我已经开始编写相应的Maven POM文件,以便可以自动进行构建和打包步骤。

JOGL is not actively maintained in Maven so I have written a small script that imports the jars via install:install-file into my local repository : 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

This results in the following files in my repo 这导致我的回购中有以下文件

.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

Note that since I specified 2.0, the files get suffixed with 2.0, eg gluegen-rt-natives-windows-i586-2.0.jar. 请注意,由于我指定了2.0,因此文件带有2.0后缀,例如,glugengen-rt-natives-windows-i586-2.0.jar。

But now I want to use the exec:java command to run the app after a build, to ensure it functions ie 但是现在我想使用exec:java命令在构建后运行应用程序,以确保其正常运行,即

mvn exec:java

So I add the exec-maven-plugin to my pom.xml 所以我将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>

And I also add the dependencies to JOGL. 并且我还将依赖项添加到JOGL。 Not that the native binaries are scoped runtime since I don't need them at compile time: 并不是说本机二进制文件是作用域范围内的运行时,因为我在编译时不需要它们:

<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>

But when I run this, I get the following error 但是当我运行它时,出现以下错误

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]

The issue is therefore straightforward. 因此,问题很简单。 I installed the jars via install:install-file and the version 2.0 was appended after the artifact id eg gluegen-rt-natives-windows-i586- 2.0 .jar, but the exec:java expects the jar to be called gluegen- 2.0 -natives-windows-i586.jar. 我通过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。

Since the project builds I must assume the compile phase is correctly looking for the jar files using the expected file name, but exec is not. 由于项目已生成,因此我必须假定编译阶段正在使用期望的文件名正确查找jar文件,但是exec却没有。

Why is it dumping the version number in the middle of the artifact id and how do I make it work properly? 为什么将版本号转储在工件ID的中间,我如何使其正常工作? The artifact id is named according to convention so I don't understand why it would be split like this. 工件ID是根据约定命名的,所以我不明白为什么会这样拆分。

Exec:java has nothing to do with your problem. Exec:java与您的问题无关。

JOGL itself has some sort of complex internal mechanism for managing native code via JNI, and that mechanism makes assumptions about file names which are incompatible with the Maven rules for naming files in the repository. JOGL本身具有某种复杂的内部机制,用于通过JNI管理本机代码,并且该机制对文件名进行了假设,这些文件名与Maven规则在存储库中命名文件不兼容。

You're going to have to use the maven-assembly-plugin to copy the dependencies to a tree that has the names and shapes required by JOGL and execute from there, or find a way to reconfigure JOGL to tolerate Maven naming conventions. 您将必须使用maven-assembly-plugin将依赖项复制到具有JOGL所需名称和形状的树,然后从那里执行,或者找到一种方法来重新配置JOGL以容许Maven命名约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven / Java-如何指定要使用的jar文件 - Maven/Java-how to specify which jar file to use Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? - Spring Boot Maven plugin - How do I build a zip file with Java jar file and script to run it? 如何从 jar 而不是 .java 文件在 S3 上创建私有 Maven 存储库? - How do I create a private Maven repository on S3 from jar not .java file? Java:如何根据类名知道要使用哪个jar文件? - Java: How do I know which jar file to use given a class name? 向maven exec添加一个jar:java classpath - add a jar to maven exec:java classpath 使用Maven的JavaFX与exec:java一起使用,但在运行时不在jar中 - JavaFX with Maven works with exec:java but not in the jar at runtime Maven exec有效,但是java -jar不起作用 - Maven exec works, but java -jar does not 如何配置Maven,以便Maven exec插件可以访问“ src /”外部目录中的配置文件 - How do I configure maven so that the maven exec plugin can access a config file in a directory outside 'src/' 如何修复 Jar 文件的 JNI 问题? - How to do I fix a JNI issue for Jar file? 如何配置install4j以运行包含其他jar文件的java可执行jar文件? - How do I configure install4j to run a java executable jar file which contains other jar files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM