Maven 和 JOGL 库?
过去几天我一直在空闲时间研究 Maven,但似乎不知道如何组织项目以便使用 JOGL 库。我最好喜欢以下内容:
- 如有必要,自动从 这里(包含4个jar文件和一些本机库文件(.so/.dll));或者依赖于 Maven 项目,它是其中一个文件的包装器。
- 适当地解压缩该 zip 文件,以便:
- 将 jar 文件添加到类路径并根据需要进行部署,并且
- 本机库文件被添加到最终的 jar 文件中(这将使它们能够自动使用,还是我需要更多的参与?)
我认为我的部分问题是我不完全理解JOGL的使用,运行代码时在哪里放置本机库等。我需要回到基础知识并编写一个JOGL hello world,从命令编译它行并从命令行运行它,以准确了解它对本机库的目录放置的要求;事实上,我现在就可以去做。
对于第 1 项,我发现了一些特定于操作系统的功能; Maven 配置文件可以根据系统的属性(包括操作系统)来激活。这样我就可以激活一个 Windows 配置文件,它依赖于 Windows 特定的 JOGL 库,对于 Linux 来说也是如此,并且两者都有一个 64 位的另一个自我。 (激活官方文档 / 非官方文档。)
我尝试过基于 JOGL jar 文件创建 Maven 存储库,然后添加 JOGL jar 文件项目作为我的项目的依赖项;依赖项已下载,但未使用。我不知道 jar 文件去了哪里,也不知道如何使用它、解压它等。 这是我使用的命令。
因此,简而言之:JOGL 由四个 .jar 文件和一些本机库组成。我如何将这些文件集成到我的 Maven 项目中,以便我可以使用 Maven 处理我的构建过程来编写 JOGL 应用程序?此外,我如何根据操作系统使用不同的文件集,因为当然Windows、Linux 和 Mac 之间的本机库甚至 .jar 文件都不同。
I've been studying Maven in my free time over the last several days but can't seem to figure out how to organize a project so that the JOGL libraries are used. I would preferably like the following:
- Automatically download, if necessary, the OS-specific JOGL zip file from here (contains 4 jar files and some native library files (.so/.dll)); or depend on a Maven project which is a wrapper of one of the files.
- Unzip that zip file appropriately, so that:
- the jar files are added to the classpath and deployed as necessary, and
- the native library files are added to the final jar file (would this enable them to be automatically used, or would I need something more involved?)
I think part of my problem is that I don't fully understand the use of JOGL, where to place the native libraries when running the code, etc. I need to go back to the basics and write a JOGL hello world, compile it from the command line and run it from the command line to see exactly what it requires as far as directory placement of the native libraries; I may go do that right now, actually.
With item 1, I've found some OS-specific features; Maven profiles can be activated based on properties of the system, which include the operating system. So then I could activate a Windows profile which has a dependency of the Windows-specific JOGL library, same for the Linux, and both having a 64-bit alter ego. (Activation official docs / unofficial docs.)
I have tried creating a Maven repository based on a JOGL jar file, and then adding the JOGL jar file project as a dependency of my project; the dependency is downloaded, but not used. I have no idea where the jar file goes or how to use it, unpack it, etc. Here is the command I used.
So, in short: JOGL consists of four .jar files and some native libraries. How can I integrate those files into my Maven project so that I can write a JOGL application with Maven handling my build process? Furthermore, how can I use a different set of files depending on the operating system, because of course the native libraries and even the .jar files differ between Windows, Linux and Mac.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
处理 JNI 和 Maven 时, Projects With JNI 是应该从参考开始的。它涵盖的内容比您当前的问题(“只是”使用依赖于 JNI 和本机库的库)要多得多,但是,谁能做得更多,谁就能做得更少。
如果您仔细阅读,您会发现使用 JNI 库的一种解决方案是将它们捆绑在特定于体系结构的 JAR 中,以便您可以从 Maven 的角度像依赖任何其他依赖项一样依赖它们。这实际上就是 JOGL 版本 1.1.1 的打包方式 http:// /download.java.net/maven/2/net/java/dev/jogl/,有一个包含 Java 类的 JAR 工件和多个包含本机库的特定于体系结构的 JAR 工件。
然后,正如所解释的,我们的想法是使用自定义库加载器来加载本机库。好消息是这样的加载器是“提供”的,如下所述。
现在,回答您的问题,如何:
遗憾的是,JOGL 2.0 jar 在 java.net 的 Maven 存储库中不可用,因此您必须处理这个问题,要么在私有存储库中提供它们,要么在每个开发人员的本地存储库中手动安装它们。为此,请使用 安装第 3 方 JAR 的指南(而不是像您那样使用
mvn deploy:deploy-file
,此目标用于将工件安装到远程存储库)。就个人而言,我会从 URL 下载 JOGL 2.0 ZIP 您提供的,将其打包,就像使用 JOGL 1.1.1 一样(一个 Java JAR 和几个用于本机库的特定 JAR),并暂时将 JAR 安装在每个本地存储库中。然后,声明对 Java 工件的标准依赖关系,并且实际上使用 profiles 作为架构特定的依赖关系。像这样的事情:
不要忘记添加自定义库加载器和依赖项所需的存储库:
关于问题的第二部分:
正如我所解释的,您实际上不会依赖于 ZIP 文件,而是依赖于 JAR,并且在开发期间或分发项目时都不需要解压缩它们。对于发行版,您只需要创建一个包含依赖项的 jar。这可以使用 Maven-Assembly-Plugin 来完成。有关更多详细信息,请参阅此答案。
When dealing with JNI and Maven, Projects With JNI is the reference one should start with. It covers a lot more than your current problem (which is "just" using a library that relies on JNI and native libraries) but, well, he who can do more can do less.
If you read it carefully, you'll see that one solution to use JNI libraries is to bundle them in architecture specific JARs so that you can depend on them like any other dependency from a Maven point of view. This is actually how JOGL version 1.1.1 is packaged in http://download.java.net/maven/2/net/java/dev/jogl/, there is one JAR artifact with the Java classes and several architecture specific JARs artifacts with the native libraries.
Then, as explained, the idea is to use a custom library loader to load the native library. The good news is that such a loader is "provided" as explained below.
Now, to answer your questions, how to:
Sadly, JOGL 2.0 jars aren't available in the Maven repository of java.net so you'll have to deal with that and either make them available in a private repository or install them manually in the local repository of each developer. To do so, use
mvn install:install-file
as documented in the Guide to installing 3rd party JARs (and notmvn deploy:deploy-file
as you did, this goal is used to install artifacts to a remote repository).Personally, I would download JOGL 2.0 ZIPs from the URL you provided, package it as they did with JOGL 1.1.1 (one Java JAR and several specific JARs for native libraries) and install the JARs in each local repository for now. Then, declare a standard dependency on the Java artifact and, indeed, use profiles for the architecture specific dependency. Something like this:
Don't forget to add the repository required for the custom library loader and the dependency:
Regarding the second part of your question:
As I explained, you actually won't depend on ZIP files but on JARs and you won't need to uncompress them neither during development nor to distribute your project. For the distribution, you'll just need to create a jar including the dependencies. This can be done with the maven-assembly-plugin. See this answer for example for more details on this.
Jogamp 现在包含对 Maven、jogl 组件的支持(jocl 和 joal 支持即将推出)。从 2.0-rc11 开始,包被推送到 Maven Central。
只需将其放入您的 pom 中即可:
下次您尝试构建项目时,Maven 将提取所有依赖项。
在 wiki 上了解更多信息
Jogamp now contains support for Maven, for the jogl components (jocl and joal support is forthcoming). As of 2.0-rc11, packages are pushed to Maven Central.
Just put this to your pom:
Maven will pull all of the dependencies the next time you attempt to build the project.
Read more here on the wiki
这里有一个 JOGL 2.0 的 Maven 存储库: http://jogamp.org/deployment/maven/
我使用 SBT 来构建我的项目。您需要添加到
build.sbt
的解析器:以及依赖项,例如,对于基本 jogl 库:
在 maven xml 文件中,这将类似于(根据 this):
依赖项声明为:
要自动下载正确的本机 jar,请在sbt 我做了类似的事情:
There is a maven repo for JOGL 2.0 here: http://jogamp.org/deployment/maven/
I use SBT for building my projects. The resolver you need to add to
build.sbt
:And the dependency, e.g., for base jogl library:
In maven xml files this would be something like (according to this):
With dependency declared as:
To automatically download proper native jar, in sbt I do something like:
我不知道 JOGL 库,但我有使用 Java3d 的经验,它有相同的安装/构建问题。有两种方法可以实现此目的:
告诉开发人员独立安装 JOGL,然后将 JOGL 库视为系统依赖项,就像我们对 Java3d 所做的那样
将所有 jar 和系统依赖库放在自己的存储库中,并为它们创建合适的 pom
如果您强烈希望通过 JOGL 的 Maven 安装实现自动化,您可以尝试使用 maven-antrun-plugin 或创建自己的 Maven 插件来处理安装(一个很好的例子是 Cargo 下载服务器并解压)。
我考虑使用第一个选项 - 告诉开发人员安装 JOGL。在我们的例子中,Java3d 应用程序是由 Java WebStart 分发的,因此对于他们来说,Java3d 的安装是由 WebStart 完全自动化的。
I don't know JOGL library but I have experience with Java3d, which has the same installation/build issues. There are two ways to achive this:
tell developers to install JOGL unassisted, then treat JOGL libraries as system dependencies like we do with Java3d
place all jars and system dependent libraries in own repository and create suitable poms for them
If you strongly want to automate with Maven installation of JOGL you can try use maven-antrun-plugin or create own Maven plugin that handles installation (a good example is Cargo that downloads servers and unpack it).
I consider to use first option - tell developers to install JOGL. In our case Java3d application is distributed by Java WebStart so for them installation of Java3d is fully automated by WebStart.
作为参考,这里是我的 Ant build.xml 文件的一部分,用于下载并解压 JOGL 库(2.0 beta 10)。
Here, for reference, is the part of my Ant build.xml file that downloads and unzips the JOGL library (2.0 beta 10).
该脚本将从 URL 下载版本并将其安装到本地(指定)存储库。
https://gist.github.com/1624599
示例用法:
./install_jogl_maven http:// /jogamp.org/deployment/v2.0-rc5 path_to_local_repo 2.0-rc5
this script will download a release from a URL and install it to a local (named) repository.
https://gist.github.com/1624599
example usage:
./install_jogl_maven http://jogamp.org/deployment/v2.0-rc5 path_to_local_repo 2.0-rc5
没有简单的方法可以实现这一点。尝试是否可以配置 maven-assemble-plugin 来构建可执行文件jar 并将正确的文件与您的代码打包在一起。您无法使用 Maven 依赖项管理来实现此目的,因为您需要 ZIP 内容而不是 ZIP 本身。您可以尝试 maven-ant-plugin。
There is no easy way to accomplish this with. Try if you can configure the maven-assembly-plugin to build a executable jar and package the correct files with your code. You cannot use the maven dependency management to achieve this because you need the ZIP contents not the ZIP itself. You could try the maven-ant-plugin.