简体   繁体   English

如何在Maven项目中包含编译的二进制文件?

[英]How can I include compiled binaries in a Maven project?

I'm developing an open source project and am trying to figure out how to incorporate the JPen library into it. 我正在开发一个开源项目,并试图弄清楚如何将JPen库合并到其中。 This is an open source library available on sourceforge that wraps drivers so you can use digital tablets in Java. 这是sourceforge上提供的开放源代码库,其中包含驱动程序,因此您可以在Java中使用数字平板电脑。

Unfortunately the project no longer seems to be maintained and the pom included in the source does not work. 不幸的是,该项目似乎不再得到维护,并且源中包含的pom无法正常工作。 I've spent some time tweaking the pom file, but am unable to get it to build. 我花了一些时间调整pom文件,但无法构建它。 Fortunately, the compiled binaries do work and I can use them in non-maven projects that I build and run with Ant. 幸运的是,已编译的二进制文件可以正常工作,并且我可以在用Ant构建和运行的非Maven项目中使用它们。

I'd like to get this working with maven cut can't find any info on how to do so. 我想让它与Maven Cut一起工作,但找不到有关该方法的任何信息。 Since this project is not published on central and since I can't build the project on my own machine, I'm left trying to figure out how to get Maven to recognize the compiled binaries as a dependency. 由于此项目未在中央发布,并且由于我无法在自己的计算机上构建该项目,因此我试图找出如何使Maven将已编译的二进制文件识别为依赖项。 These libraries include some compiled binaries using JNI, so that may throw in a twist beyond just including a jar file. 这些库包括一些使用JNI编译的二进制文件,因此可能不仅仅包括jar文件,还可能带来一些麻烦。

Anyone know how I would add this dependency to my maven project? 任何人都知道如何将这种依赖关系添加到我的Maven项目中吗?

In your case the fast way to solve using Maven it to install the jar as a dependency manually, as explained in the Maven documentation linked in my comment . 在您的情况下,使用Maven解决该问题的快速方法是手动安装jar作为依赖项,如我的注释中链接的Maven文档中所述。

You can use the following command: 您可以使用以下命令:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

Providing a proper group-id , artifact-id , version and packagin you have all the info to import the dependency in your pom file: 提供适当的group-idartifact-idversionpackagin,您就拥有了将依赖项导入到pom文件中的所有信息:

<dependencies>
    ...
    <dependency>
        <groupId><group-id></groupId>
        <artifactId><artifact-id></artifactId>
        <version><version></version>
    </dependency>
    ...
</dependencies>

That will solve the build problem on your machine. 这样可以解决您机器上的构建问题。

If you share your project, than you have to perform a step further. 如果您共享您的项目,则必须执行进一步的步骤。

If you share in your company, than is a good practice to have an internal repository like artifactory or nexus . 如果您与公司共享股份,那么最好使用内部构件(例如artifactorynexus)

In such case you just need to upload your new local dependency manually to your company repository and then all your coulleuges should be able to build your project without any manual action. 在这种情况下,您只需要手动将新的本地依赖项上载到公司资源库,然后所有合规性就可以构建您的项目,而无需任何手动操作。

If you want to publish your project as an open source project and make it available for every one, than you have a different path to follow. 如果您想将项目发布为一个开源项目并使每个项目都可用,那么您将有一条不同的路要走。

You can just add the dependency on your pom, then write on the README how to install manually the jar and where to obtain it. 您可以仅将依赖项添加到pom上,然后在自述文件中编写如何手动安装jar以及从何处获取它。

The last possibility I see, is that you take ownership of the project making a fork. 我看到的最后一种可能性是,您拥有该项目的所有权。

That should be always possible with open source license, but take care and have a look of it. 使用开放源代码许可证应该总是有可能的,但是请多加注意。

Once you fork the code, you have to build it your own, I read you can't do it, but you should fix the problems and make a build. 派生代码后,您必须自己构建代码,我读到您无法执行,但是您应该解决问题并进行构建。

At that point you're able to publish on Maven central repository. 到那时,您就可以在Maven中央存储库上发布了。

A good starting point is to contact the original author and ask for permission and help to do that. 一个好的起点是与原始作者联系,并寻求许可和帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM