如何在 Maven 中添加 javax.* 依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1044919/
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
How to add javax.* dependencies in Maven?
提问by pjesi
I am getting tired of manually installing javax jar files in Maven and would like to know what is the best solution to include a dependency on javax.cache, javax.transaction, or other JSRs that are not easy to find in Maven repositories.
我厌倦了在 Maven 中手动安装 javax jar 文件,想知道包含对 javax.cache、javax.transaction 或其他在 Maven 存储库中不容易找到的 JSR 的依赖的最佳解决方案是什么。
采纳答案by matt b
Have you seen http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html?
你见过http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html吗?
This link suggests groupID and artifactID's to use, as well as a java.net repository.
此链接建议使用 groupID 和 artifactID,以及 java.net 存储库。
It looks to me like almost all of these exist in the central Maven repository under this naming scheme.
在我看来,在这个命名方案下,几乎所有这些都存在于中央 Maven 存储库中。
回答by Jon
I'm not aware of one, but adding the java.net repository may help you with some of these dependencies:
我不知道有一个,但添加 java.net 存储库可能会帮助您解决其中一些依赖项:
<repositories>
<repository>
<id>java.net repository</id>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
回答by victor hugo
javax.cache
are in jcache:jcache:1.0-XXX
artifact (in Maven's central repo)
javax.cache
在jcache:jcache:1.0-XXX
工件中(在 Maven 的中央仓库中)
<dependency>
<groupId>jcache</groupId>
<artifactId>jcache</artifactId>
<version>1.0-dev-2</version>
</dependency>
javax.transaction.*
classes are in javax.transaction:jta:1.1
artifact, JTA jar can't be inserted in the Maven repository because the Sun's Binary License (I know, this sucks). To use it you need to download manually the JAR (it's free) and put it into a local repo or use 1.0.1B version which is contained in java.net
.
javax.transaction.*
类在javax.transaction:jta:1.1
工件中,JTA jar 不能插入到 Maven 存储库中,因为 Sun 的二进制许可证(我知道,这很糟糕)。要使用它,您需要手动下载 JAR(它是免费的)并将其放入本地存储库或使用包含在java.net
.
NOTE: I've read in some place JTA will be integrated in future versions of the JDK
注意:我在某些地方读到 JTA 将被集成到 JDK 的未来版本中
I know is really a pain to find these artifacts in Maven's repositories but you can make a search of a class in www.mvnrepository.comand it will show you the correct groupId and artifactId for mostly all the packages.
我知道在 Maven 的存储库中找到这些工件确实很痛苦,但是您可以在www.mvnrepository.com 中搜索一个类,它会向您显示大多数包的正确 groupId 和 artifactId。
回答by michael
If building on more than one box and/or for team development, a local (intranet) maven repository manager can help with these "missing" jars. This centralizes the configuration and management of not only 3rd party jars that are not in a public repository, but also all external repositories in general. It could also help automate your builds, creating more 'reproducable' builds (e.g., if you have a pool of continuous integration servers).
如果构建在多个盒子上和/或用于团队开发,则本地(内联网)maven 存储库管理器可以帮助处理这些“丢失”的 jar。这不仅集中了不在公共存储库中的 3rd 方 jar 的配置和管理,而且还集中了所有外部存储库的配置和管理。它还可以帮助自动化您的构建,创建更多“可重复”的构建(例如,如果您有一个持续集成服务器池)。
- install a mvn repo mgr (see list -- imo, nexus is really simple to start with);
- use a custom settings.xml that includes a "mirrors" section pointing to your intranet mvn repo mgr. Either update your ~/.m2/settings.xml, or run maven with "mvn -s etc/settings.xml"-- useful for hudson builds, where you don't want a custom per-user settings.xml;
- manually upload your 'problem' jars to your internal repo (again, super-simple w/ Nexus via a web-interface);
- set up the internal mvn repo mgr as a "mirror" of repo1.maven.org/maven2, codehaus, java.net, ... (etc).
- 安装一个 mvn repo mgr(见列表——imo,nexus 很容易上手);
- 使用自定义 settings.xml,其中包含指向您的 Intranet mvn repo mgr 的“镜像”部分。要么更新你的 ~/.m2/settings.xml,要么用“mvn -s etc/settings.xml”运行 maven——这对 hudson 构建很有用,在这种情况下你不需要自定义的每个用户 settings.xml;
- 手动将您的“问题”罐子上传到您的内部存储库(同样,通过网络界面使用 Nexus 非常简单);
- 将内部 mvn repo mgr 设置为 repo1.maven.org/maven2、codehaus、java.net、...(等)的“镜像”。
Now, you can centrallydefine all 3rd party repositories & 3rd party jars -- rather than requiring each person, each box and/or each project define them individually in their pom or settings.xml. Each project / person / box would ONLY define your central, internal maven repo as the single repo for all maven projects.
现在,您可以 集中定义所有 3rd 方存储库和 3rd 方 jars——而不是要求每个人、每个盒子和/或每个项目在他们的 pom 或 settings.xml 中单独定义它们。每个项目/人/框只会将您的中央内部 Maven 存储库定义为所有 Maven 项目的单个存储库。
This also reallyspeeds up your artifact re-download time for fresh builds, or for those times when you need to (or would like to) delete your local ~/.m2/repository cache.
这也确实加快了新构建的工件重新下载时间,或者在您需要(或想要)删除本地 ~/.m2/repository 缓存时。
Repo managers: nexus, archiva, artifactory... e.g.,: maven.apache.org/repository-management.html - http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix
存储库管理器:nexus、archiva、artifactory... 例如:maven.apache.org/repository-management.html - http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix
回答by RickB
In the particular case of JTA, I hit this post:
在 JTA 的特殊情况下,我点击了这篇文章:
http://www.jugpadova.it/articles/2005/11/26/maven-2-spring-and-jta-depencies
.. which makes sense, if I didn't have to spend a lot of time in Oracle's horrible site to get the forementioned JAR file. (I was an Oracle's enthusiast myself but that site could use a lot of UX rework here and there).
.. 这是有道理的,如果我不必在 Oracle 的可怕站点上花费大量时间来获取上述 JAR 文件。(我本人是 Oracle 的狂热爱好者,但该站点可以在这里和那里使用大量 UX 返工)。
I decided to replace the dependency with what Hibernate provides, via Geronimo, as per this post (worked perfectly):
我决定用 Hibernate 通过 Geronimo 提供的内容替换依赖项,按照这篇文章(完美运行):
https://forum.hibernate.org/viewtopic.php?p=2420836
The deal with Java licensing and Maven is currently being worked on by the Hibernate team, or so it seems here:
Hibernate 团队目前正在处理 Java 许可和 Maven 的交易,或者在这里看起来是这样的:
https://hibernate.onjira.com/browse/HHH-4548
Thanks to everyone for sharing!
感谢大家的分享!