1

我的 Java 项目有许多依赖项,例如,Box2d我在我的 中定义 了以下 s 列表,因此使用 Maven 来管理项目。 注意:我在底部列出了依赖项,但不包括在此处。OpenGlOpenAl
pluginpom.xml
pom.xml

我按照这个文档开始:http ://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source/>
            <target/>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.app.game.Main</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

当我运行时mvn packagejar会创建 a ,即target/test-0.1.jar
它实际上包含所有jar依赖项,并在包的根目录中包含本机.so和库。.dll

在此处输入图像描述

但是当我尝试从 CLI 运行应用程序时,我得到了UnsatisfiedLinkError异常。
我错过了什么pom吗?

[rob@work target]$ java -jar test-0.1.jar 
log4j:WARN No appenders could be found for logger (com.app.game.Main).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Catched FileNotFoundException: /home/rob/git/test/target/test-0.1-natives-linux-amd64.jar (No such file or directory), while addNativeJarLibsImpl(classFromJavaJar class com.jogamp.common.os.Platform, classJarURI jar:file:/home/rob/git/test/target/test-0.1.jar!/com/jogamp/common/os/Platform.class, nativeJarBaseName test-0.1-natives-linux-amd64.jar): [ file:/home/rob/git/test/target/test-0.1.jar -> file:/home/rob/git/test/target/ ] + test-0.1-natives-linux-amd64.jar -> slim: jar:file:/home/rob/git/test/target/test-0.1-natives-linux-amd64.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/rob/git/test/target/libgluegen-rt.so (/home/rob/git/test/target/liblibgluegen-rt.so.so: cannot open shared object file: No such file or directory)
    at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:1217)
4

1 回答 1

0

使用下面的一组plugins实现POM.xml了我想要的..

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <descriptors>
            <descriptor>src/assembly/assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>  <!-- this is used for inheritance merges -->
            <phase>verify</phase>  <!-- bind to the verify phase, to execute after package phase -->
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>appassembler-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <programs>
            <program>
                <mainClass>com.app.game.Main</mainClass>
                <id>thegame</id>
            </program>
        </programs>
        <repositoryName>lib</repositoryName>
        <repositoryLayout>flat</repositoryLayout>
        <assembleDirectory>${project.build.directory}/${project.artifactId}</assembleDirectory>
    </configuration>
    <executions>
        <execution>
            <id>prepare-assembly</id>  <!-- this is used for inheritance merges -->
            <phase>package</phase>  <!-- bind to the package phase -->
            <goals>
                <goal>assemble</goal>
            </goals>
        </execution>
    </executions>
</plugin>

src/assembly/assembly.xml..

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/${project.artifactId}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>/**</include>
            </includes>
            <excludes>
                <exclude>bin/*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/${project.artifactId}/bin</directory>
            <lineEnding>keep</lineEnding>
            <useDefaultExcludes>true</useDefaultExcludes>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*</include>
            </includes>
            <fileMode>755</fileMode>
        </fileSet>
    </fileSets>
</assembly>
于 2014-08-31T15:36:36.203 回答