使用 maven 和 ubuntu 将 java.library.path 添加到 /usr/lib/jni for scala

发布于 2024-11-27 16:27:23 字数 9512 浏览 0 评论 0原文

我正在尝试创建一个 pom.xml 来编译并运行 scala 中的程序。 该项目需要一些 *.so 库(例如gluegen-rt.so)才能运行。这些文件位于此处:/usr/lib/jni/

当我运行程序时出现此错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at com.jogamp.gluegen.runtime.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:102)
    at com.jogamp.gluegen.runtime.NativeLibLoader.access$000(NativeLibLoader.java:51)
    at com.jogamp.gluegen.runtime.NativeLibLoader$1.run(NativeLibLoader.java:70)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.jogamp.gluegen.runtime.NativeLibLoader.loadGlueGenRT(NativeLibLoader.java:68)
    at com.jogamp.common.jvm.JVMUtil.<clinit>(JVMUtil.java:56)
    at javax.media.nativewindow.NativeWindowFactory.<clinit>(NativeWindowFactory.java:102)
    at javax.media.opengl.awt.GLCanvas.<clinit>(GLCanvas.java:82)
    at org.jzy3d.chart.Chart.initializeCanvas(Chart.java:65)
    at org.jzy3d.chart.Chart.<init>(Chart.java:56)
    at org.jzy3d.chart.Chart.<init>(Chart.java:39)
    at fr.iscpif.slocalfit.testGraphique$.main(testGraphique.scala:28)
    at fr.iscpif.slocalfit.testGraphique.main(testGraphique.scala)

所以我使用 Maven 对链接库进行了一些研究,并且我在 pom.xml 上找到了此命令行:

<systemProperties>
<property>
<name>java.library.path</name>
<value>/usr/lib/jni/</value>
</property>
</systemProperties>

但我不'不知道在哪里可以将这行代码写入到我的pom.xml中,因为我希望maven在运行程序的主类之前将这些行添加到java命令行中.. 。

此致, 感谢您的帮助,

我的 pom.xml 实际上是这样的:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fr.iscpif</groupId>
    <packaging>bundle</packaging>
    <artifactId>slocalfit</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${lib.org.scala-lang.scala.version}</version>
            <!--<scope>provided</scope>-->
        </dependency>
        <dependency>
            <groupId>javax.media.opengl</groupId>
            <artifactId>jogl-core</artifactId>
            <version>2.0-pre-20101001</version> 
        </dependency>
        <dependency>
            <groupId>javax.media.opengl</groupId>
            <artifactId>jogl-util</artifactId>
            <version>2.0-pre-20101001</version>
        </dependency>
        <dependency>

            <groupId>javax.media.nativewindow</groupId>
            <artifactId>nativewindow-core</artifactId>    
            <version>2.0-pre-20101001</version>
        </dependency>

        <dependency>
            <groupId>com.jogamp.gluegen</groupId>
            <artifactId>gluegen-rt</artifactId>    
            <version>1.0-beta07</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>3.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>ca.umontreal.iro</groupId>
            <artifactId>ssj</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>gov.lbl.acs.colt</groupId>
            <artifactId>colt</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.13</version>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jcommon</artifactId>
            <version>1.0.15</version>
        </dependency>
        <dependency>
            <groupId>org.openmole.tools</groupId>
            <artifactId>mgo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.openmole</groupId>
            <artifactId>au.com.bytecode.opencsv</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org</groupId>
            <artifactId>jzy3d</artifactId>
            <version>0.9</version>
        </dependency>
    </dependencies>

    <properties>
        <lib.org.scala-lang.scala.version>2.9.0-1</lib.org.scala-lang.scala.version>
        <maven.scala.version>${lib.org.scala-lang.scala.version}</maven.scala.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                        </configuration>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>${run.mainclass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>-->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <manifestLocation>target/META-INF</manifestLocation>
                    <finalName>${symbolic.name}_${project.version}</finalName>
                    <instructions>
                        <!--<Main-Class>fr.iscpif.TON.PACKAGE.TaClasse</Main-Class>-->
                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*;resolution:=optional</Import-Package>
                        <Export-Package>fr.iscpif.slocalfit.*,org.apache.commons.math.*,org.openmole.tools.mgo.*,umontreal.iro.lecuyer.*</Export-Package>
                        <Embed-Dependency>*;scope=!provided;inline=true;artifactId=!scala-library</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <name>${project.artifactId} ${project.version}</name>


    <repositories>
        <repository>
            <id>maven.iscpif.fr</id>
            <name>ISCPIF repository</name>
            <url>http://maven.iscpif.fr/public/</url>
        </repository>
        <repository>
            <id>maven.iscpif.fr.snapshots</id>
            <name>ISCPIF snapshots repository</name>
            <url>http://maven.iscpif.fr/snapshots/</url>
        </repository>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala repository</name>
            <url>http://scala-tools.org/repo-releases/</url>
        </repository>
    </repositories>

</project>

I'm trying to create a pom.xml which compile and run a program in scala.
This project need some *.so libraries (gluegen-rt.so for example) to run. Theses files are located here : /usr/lib/jni/

I have this error when i run my program :

Exception in thread "main" java.lang.UnsatisfiedLinkError: no gluegen-rt in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at com.jogamp.gluegen.runtime.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:102)
    at com.jogamp.gluegen.runtime.NativeLibLoader.access$000(NativeLibLoader.java:51)
    at com.jogamp.gluegen.runtime.NativeLibLoader$1.run(NativeLibLoader.java:70)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.jogamp.gluegen.runtime.NativeLibLoader.loadGlueGenRT(NativeLibLoader.java:68)
    at com.jogamp.common.jvm.JVMUtil.<clinit>(JVMUtil.java:56)
    at javax.media.nativewindow.NativeWindowFactory.<clinit>(NativeWindowFactory.java:102)
    at javax.media.opengl.awt.GLCanvas.<clinit>(GLCanvas.java:82)
    at org.jzy3d.chart.Chart.initializeCanvas(Chart.java:65)
    at org.jzy3d.chart.Chart.<init>(Chart.java:56)
    at org.jzy3d.chart.Chart.<init>(Chart.java:39)
    at fr.iscpif.slocalfit.testGraphique$.main(testGraphique.scala:28)
    at fr.iscpif.slocalfit.testGraphique.main(testGraphique.scala)

So i make some research on linked library with maven, and i find this command line on a pom.xml :

<systemProperties>
<property>
<name>java.library.path</name>
<value>/usr/lib/jni/</value>
</property>
</systemProperties>

But i don't know where i can write this lines into my pom.xml, because i want maven add this lines to java command line before i run the main class of my program ...

Best regards,
Thanks for help,

My pom.xml is actually like that :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>fr.iscpif</groupId>
    <packaging>bundle</packaging>
    <artifactId>slocalfit</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${lib.org.scala-lang.scala.version}</version>
            <!--<scope>provided</scope>-->
        </dependency>
        <dependency>
            <groupId>javax.media.opengl</groupId>
            <artifactId>jogl-core</artifactId>
            <version>2.0-pre-20101001</version> 
        </dependency>
        <dependency>
            <groupId>javax.media.opengl</groupId>
            <artifactId>jogl-util</artifactId>
            <version>2.0-pre-20101001</version>
        </dependency>
        <dependency>

            <groupId>javax.media.nativewindow</groupId>
            <artifactId>nativewindow-core</artifactId>    
            <version>2.0-pre-20101001</version>
        </dependency>

        <dependency>
            <groupId>com.jogamp.gluegen</groupId>
            <artifactId>gluegen-rt</artifactId>    
            <version>1.0-beta07</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>3.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>ca.umontreal.iro</groupId>
            <artifactId>ssj</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>gov.lbl.acs.colt</groupId>
            <artifactId>colt</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.13</version>
        </dependency>
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jcommon</artifactId>
            <version>1.0.15</version>
        </dependency>
        <dependency>
            <groupId>org.openmole.tools</groupId>
            <artifactId>mgo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.openmole</groupId>
            <artifactId>au.com.bytecode.opencsv</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org</groupId>
            <artifactId>jzy3d</artifactId>
            <version>0.9</version>
        </dependency>
    </dependencies>

    <properties>
        <lib.org.scala-lang.scala.version>2.9.0-1</lib.org.scala-lang.scala.version>
        <maven.scala.version>${lib.org.scala-lang.scala.version}</maven.scala.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                        </configuration>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>${run.mainclass}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>-->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <manifestLocation>target/META-INF</manifestLocation>
                    <finalName>${symbolic.name}_${project.version}</finalName>
                    <instructions>
                        <!--<Main-Class>fr.iscpif.TON.PACKAGE.TaClasse</Main-Class>-->
                        <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*;resolution:=optional</Import-Package>
                        <Export-Package>fr.iscpif.slocalfit.*,org.apache.commons.math.*,org.openmole.tools.mgo.*,umontreal.iro.lecuyer.*</Export-Package>
                        <Embed-Dependency>*;scope=!provided;inline=true;artifactId=!scala-library</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <name>${project.artifactId} ${project.version}</name>


    <repositories>
        <repository>
            <id>maven.iscpif.fr</id>
            <name>ISCPIF repository</name>
            <url>http://maven.iscpif.fr/public/</url>
        </repository>
        <repository>
            <id>maven.iscpif.fr.snapshots</id>
            <name>ISCPIF snapshots repository</name>
            <url>http://maven.iscpif.fr/snapshots/</url>
        </repository>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala repository</name>
            <url>http://scala-tools.org/repo-releases/</url>
        </repository>
    </repositories>

</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

跨年 2024-12-04 16:27:24

我从未使用过 Maven,但经常使用 JNI。

您是否在所使用的 IDE 中指定了本机库路径?
如果您使用 NetBeans 或 Eclipse 等 IDE,则在将 .jar 文件添加到 IDE 时,必须指定 Java 本机库(对于某些 java .jar 库所在)的位置(我的意思是 .dll 或 .so)。

对于前。在 Eclipse 中:右键单击项目 ->属性-> Java 构建路径 ->库(在选项卡栏上)->单击该库(并将其展开),您可以在其中找到本机库位置。您只需指定 .so 文件所在的路径。
您必须在 NetBeans 上执行类似的过程:我认为您必须按“项目属性”->“图书馆,你可以找到这些东西。

希望它有帮助:)

I have never worked with maven but a lot with JNI.

Have you specified the Native Library Path in the IDE that you´re using?
If you use IDE like NetBeans or Eclipse you have to specify where the Java Native Library (for certain java .jar library is) is located (I mean the .dll or .so) when adding the .jar files to IDE.

For ex. in Eclipse: Right click on project -> Properties -> Java Build Path -> Libraries (on the tab bar) -> Click on the library (and expand it) and there you can find Native library location. You have only to specify the path where .so files are located.
You have to do similar procedure on NetBeans: I think you have to press Project Properties -> Libraries and there you find these things.

Hope it was helpful :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文