我正在尝试获取一个与 Gradle 一起使用的示例 LWJGL 应用程序。 LWJGL 在 lwjgl-platform-2.8.5-natives-windows.jar 等 jar 中具有 OpenGL 和 OpenAL 的 native 绑定(bind),但是,Gradle 似乎没有认识到这一事实。
应用程序插件的 distZip 任务正确地将所有 jar 文件复制到 zip 中的 lib 目录中,但是,在 .bat 文件中,它仅将上述 native jar 放在类路径上,不会将其作为显式 native 传递给 java .
同样,Eclipse 项目生成也无法设置给定依赖项的“ native 库位置”。
是否有任何官方解决方案可以将 native 库正确添加到生成的应用程序或 Eclipse 项目中,如果没有,是否有任何解决此限制的好方法?
我的gradle.build:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
mainClassName = 'org.lwjgl.examples.Game'
repositories {
mavenCentral();
}
dependencies {
compile group: 'com.google.guava', name: 'guava', version: 'latest.release'
compile group: 'org.apache.commons', name: 'commons-lang3', version: 'latest.release'
compile group: 'org.lwjgl.lwjgl', name: 'lwjgl', version: 'latest.release'
testCompile group: 'com.jayway.awaitility', name: 'awaitility', version: 'latest.release'
testCompile group: 'junit', name: 'junit', version: 'latest.release'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: 'latest.release'
testCompile group: 'org.mockito', name: 'mockito-core', version: 'latest.release'
}
jar {
baseName = rootProject.name
version = System.env['BUILD_NUMBER']
version = version == null ? 0 : version
manifest {
attributes("Implementation-Title": baseName, "Implementation-Version": version)
}
}
生成的zip分发内容:
/lib//bin/tyle
/lib//bin/tyle.bat
/lib/commons-lang3-3.1.jar
/lib/guava-14.0-rc2.jar
/lib/jinput-2.0.5.jar
/lib/jinput-platform-2.0.5-natives-linux.jar
/lib/jinput-platform-2.0.5-natives-osx.jar
/lib/jinput-platform-2.0.5-natives-windows.jar
/lib/jutils-1.0.0.jar
/lib/lwjgl-2.8.5.jar
/lib/lwjgl-platform-2.8.5-natives-linux.jar
/lib/lwjgl-platform-2.8.5-natives-osx.jar
/lib/lwjgl-platform-2.8.5-natives-windows.jar
/lib/tyle-0.jar
lwjgl-platform-2.8.5-natives-windows.jar 的内容:
META-INF/MANIFEST.MF
lwjgl.dll
lwjgl64.dll
OpenAL32.dll
OpenAL64.dll
最佳答案
我一直在努力解决类似的问题,并已启动 Gradle Natives Plugin用于管理 Java 库的 native 依赖项。另请参阅博客文章“Going Native with Gradle”,其中我将介绍更多详细信息。
基本上,它将提供的 native 库解压到“natives”构建目录中以供使用和进一步打包。
关于eclipse - 使用 JNI 依赖项、应用程序和 eclipse 插件构建 Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14655220/