Java 使用包含的专有库构建 maven 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4491199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
build maven project with propriatery libraries included
提问by London
How to create maven pom, which will make project buildable, can I include propriatery jars with my project directly without having to take them from repository? anyone did this before ?
如何创建 maven pom,这将使项目可构建,我可以直接在我的项目中包含专有 jars 而不必从存储库中获取它们吗?以前有人这样做过吗?
EDIT :
编辑 :
I don't want to make it runnable by building assembly with dependencies jar, I want it to be buildable. So anyone having this project is able to build it, even if jars are nowhere to be found at any repository.
我不想通过使用依赖项 jar 构建程序集来使其可运行,我希望它是可构建的。因此,任何拥有此项目的人都可以构建它,即使在任何存储库中都找不到 jar。
采纳答案by Jigar Joshi
1Either you can include that jar in your classpath of application
2you can install particular jar file in your maven reopos by
1您可以在应用程序的类路径中包含该 jar
2您可以通过以下方式在您的 maven reopos 中安装特定的 jar 文件
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
回答by jvdbogae
You can use the maven-assembly-pluginand create a jar with all dependencies included.
您可以使用maven-assembly-plugin并创建一个包含所有依赖项的 jar。
回答by David J. Liszewski
You could either add the jar to your project and mess around with the maven-assembly-plugin, or add the jar to your local repository:
您可以将 jar 添加到您的项目中并使用 maven-assembly-plugin,或者将 jar 添加到您的本地存储库:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
回答by Larry Shatzer
Why not run something like Nexus, your own maven repo that you can upload 3rd party proprietary jar files, and also proxy other public repositories, to save on bandwith?
为什么不运行像Nexus这样的东西,你自己的 maven 存储库,你可以上传 3rd 方专有 jar 文件,还代理其他公共存储库,以节省带宽?
Thisalso has some good reasons to run your own maven repository manager.
这也有一些很好的理由来运行您自己的 Maven 存储库管理器。
回答by 01es
A good way to achieve this is to have a Maven mirror server such as Sonatype Nexus. It is free and very easy to setup (Java web app). With Nexus one can have private (team, corporate etc) repository with a capability of deploying third party and internal apps into it, while also registering other Maven repositories as part of the same server. This way the local Maven settings would reference only the one private Nexus server and all the dependencies will be resolved using it.
实现这一目标的一个好方法是拥有一个 Maven 镜像服务器,例如Sonatype Nexus。它是免费的并且非常容易设置(Java Web 应用程序)。使用 Nexus,您可以拥有私有(团队、公司等)存储库,能够将第三方和内部应用程序部署到其中,同时还可以将其他 Maven 存储库注册为同一服务器的一部分。这样,本地 Maven 设置将仅引用一个私有 Nexus 服务器,并且所有依赖项都将使用它来解决。
回答by ant
Possible solutions is put your dependencies in src/main/resources then in your pom :
可能的解决方案是将您的依赖项放在 src/main/resources 中,然后放在您的 pom 中:
<dependency>
groupId ...
artifactId ...
version ...
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
Note: system dependencies are not copied into resulted jar/war
(see How to include system dependencies in war built using maven)
注意:系统依赖项不会复制到结果 jar/war 中
(请参阅如何在使用 maven 构建的 war 中包含系统依赖项)
回答by AlexR
I think that the "right" solution here is to add your proprietary libraries to your own repository. It should be simple: create pom for your library project and publish the compiled version on your repository. Add this repository to the list of repositories for your mail project and run build. I believe it will work for you.
我认为这里“正确”的解决方案是将您的专有库添加到您自己的存储库中。它应该很简单:为您的库项目创建 pom 并将编译后的版本发布到您的存储库中。将此存储库添加到邮件项目的存储库列表中并运行 build。我相信它对你有用。
回答by Alireza Fattahi
You can get it from your local driver as below:
您可以通过以下方式从本地驱动程序获取它:
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
回答by mostar
Create a repository folder under your project. Let's take
在您的项目下创建一个存储库文件夹。让我们来
${project.basedir}/src/main/resources/repo
Then, install your custom jar to this repo:
然后,将您的自定义 jar 安装到此 repo:
mvn install:install-file -Dfile=[FILE_PATH] \
-DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] \
-Dpackaging=jar -DlocalRepositoryPath=[REPO_DIR]
Lastly, add the following repo and dependency definitions to the projects pom.xml:
最后,将以下 repo 和依赖项定义添加到项目 pom.xml 中:
<repositories>
<repository>
<id>project-repo</id>
<url>file://${project.basedir}/src/main/resources/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>[GROUP]</groupId>
<artifactId>[ARTIFACT]</artifactId>
<version>[VERS]</version>
</dependency>
</dependencies>
回答by fl0w
The really quick and dirty way is to point to a local file:
真正快速而肮脏的方法是指向本地文件:
<dependency>
<groupId>sampleGroupId</groupId>
<artifactId>sampleArtifactId</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\DEV\myfunnylib\yourJar.jar</systemPath>
</dependency>
However this will only live on your machine (obviously), for sharing it usually makes sense to use a proper m2 archive (nexus/artifactory) or if you do not have any of these or don't want to set one up a local maven structured archive and configure a "repository" in your pom: local:
但是,这只会存在于您的机器上(显然),为了共享,使用适当的 m2 存档(nexus/artifactory)通常是有意义的,或者如果您没有这些存档或不想设置本地 maven结构化存档并在您的 pom 中配置一个“存储库”:本地:
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://C:/DEV//mymvnrepo</url>
</repository>
</repositories>
remote:
偏僻的:
<repositories>
<repository>
<id>my-remote-repo</id>
<url>http://192.168.0.1/whatever/mavenserver/youwant/repo</url>
</repository>
</repositories>