0

我正在 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 为后缀,例如,gluegen-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 安装了 jars,并且版本 2.0 被附加在工件 id 之后,例如gluegen-rt-natives-windows-i586- 2.0 .jar,但是 exec:java 期望 jar 被称为gluegen- 2.0 - natives-windows-i586.jar。

由于项目构建,我必须假设编译阶段使用预期的文件名正确查找 jar 文件,但 exec 不是。

为什么它会在工件 id 中间转储版本号,如何使其正常工作?工件 id 是根据约定命名的,所以我不明白为什么会这样拆分。

4

1 回答 1

3

Exec:java 与您的问题无关。

JOGL 本身具有某种复杂的内部机制,用于通过 JNI 管理本机代码,并且该机制对文件名做出假设,这些假设与 Maven 存储库中的文件命名规则不兼容。

您将不得不使用 maven-assembly-plugin 将依赖项复制到具有 JOGL 所需的名称和形状的树并从那里执行,或者找到一种重新配置 JOGL 以容忍 Maven 命名约定的方法。

于 2013-01-09T12:23:42.683 回答