pjesi
pjesi

Reputation: 4051

How to add javax.* dependencies in Maven?

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.

Upvotes: 25

Views: 55378

Answers (5)

matt b
matt b

Reputation: 139921

Have you seen https://people.apache.org/~ltheussl/maven-stage-site/guides/mini/guide-coping-with-sun-jars.html ?

This link suggests groupID and artifactID's to use, as well as a java.net repository.

It looks to me like almost all of these exist in the central Maven repository under this naming scheme.

Upvotes: 13

RickB
RickB

Reputation: 653

In the particular case of JTA, I hit this post:

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).

I decided to replace the dependency with what Hibernate provides, via Geronimo, as per this post (worked perfectly):

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:

https://hibernate.onjira.com/browse/HHH-4548

Thanks to everyone for sharing!

Upvotes: 2

Jonathan Holloway
Jonathan Holloway

Reputation: 63662

I'm not aware of one, but adding the java.net repository may help you with some of these dependencies:

<repositories>
   <repository>
      <id>java.net repository</id>
      <url>http://download.java.net/maven/2</url>
   </repository>
</repositories>

Upvotes: 7

victor hugo
victor hugo

Reputation: 35838

javax.cache are in jcache:jcache:1.0-XXX artifact (in Maven's central repo)

<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.

NOTE: I've read in some place JTA will be integrated in future versions of the 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.com and it will show you the correct groupId and artifactId for mostly all the packages.

Upvotes: 3

michael
michael

Reputation: 9759

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).

  1. install a mvn repo mgr (see list -- imo, nexus is really simple to start with);
  2. 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;
  3. manually upload your 'problem' jars to your internal repo (again, super-simple w/ Nexus via a web-interface);
  4. set up the internal mvn repo mgr as a "mirror" of repo1.maven.org/maven2, codehaus, java.net, ... (etc).

Now, you can centrally define 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.

This also really speeds 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.

Repo managers: nexus, archiva, artifactory... e.g.,: maven.apache.org/repository-management.html - http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix

Upvotes: 5

Related Questions