views:

42

answers:

3

Hi!

I'm getting build errors for for my Maven enabled project related to the Hibernate extension. - It's a very basic app, and I was able to solve this issue on my Linux box by manually installing some required artifacts:

mvn install:install-file -DgroupId=javassist -DartifactId=javassist 
-Dversion=3.9.0 -Dpackaging=jar -Dfile=foo.jar

That worked out (Hibernate as a set of required deps).

But in case of Windows things are different. How do I add the dependencies manually to Maven on Windows?

    1) org.hibernate:hibernate:jar:3.3.2

      Try downloading the file manually from the project website.

      Then, install it using the command: 
          mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate -Dversion=3.3.2 
-Dpackaging=jar -Dfile=/path/to/file

   2) javassist:javassist:jar:3.9.0

Can I automate this cumbersome manual dependency installation for my coworkers on their Windows machines? Are there any helpful tools or GUI that can perform these tasks? The best way would be that Maven does it all automatically. I'm not too familiar with it jet.

Thanks for answers.

+1  A: 
  1. You can use mvn install:install-file on your Windows machine to install dependencies to the local repository as well
  2. You might want to change your settings.xml to add additional repository mirrors, so you aren't relying on just central. Check out jboss, java.net, etc. You can also set up your own repository manager (like Nexus) to handle mirroring, storing your team's artifacts, etc.; and then just point each developers machine at your repository.

See Repository Management with Nexus and Reasons to use a Repository Manager for more.

matt b
+1  A: 

Firstly, you can manually install artifacts to your local Maven repository in Windows in exactly the same way you did on your Linux box.

Ideally, as you say, Maven will do the hard work for you. Usually you won't have to install jars manually: for most libraries Maven will know what dependencies each jar has. By default, Maven will check the central repository, and a couple of others. To access jars in other repositories, just add them to your POM, as follows:

  <project>
      ...
      <repositories>
          <repository>
              <id>jboss.maven2.repo</id>
              <name>JBoss Maven Repo</name>
              <url>http://repository.jboss.com/maven2&lt;/url&gt;
          </repository>
          <!-- other repositories here -->
      </repositories>
      ...
  </project>

The JBoss repo mentioned above is a good one to add. It has a lot of common jars, including the jars for the hibernate version you mentioned above. Reference it in your pom.xml like this:

<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.2.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.4.0.GA</version>
    </dependency>
</dependencies>

Once you have added these dependencies, Maven will also download the libraries that these libraries depend on, and so on (including the Javassist library in your example).

Finally, as mentioned in another answer, if you have a lot of third party libraries to install for your project that don't exist in other repositories, you might want to install a repository manager like Nexus, Artifactory, or Archiva, which will allow you to perform the install commands you mentioned, through a web-based interface.

Daniel
That's not the right dependency for hibernate (the one mentioned here is just a pom).
Pascal Thivent
Good point :) : updated. The new version is tested. Thanks for the correction
Daniel
+1  A: 

I was able to solve this issue on my Linux box by manually installing some required artifacts (...)

Manually installing an artifact is a bad practice (it makes your build non portable as you're experiencing) and, actually, there is no reason to install the artifacts you're looking for manually, they're both available in the JBoss repository. So, add it to the list of "declared" repositories:

<project>
  ...
  <repositories>
    <repository>
      <id>repository.jboss.org</id>
      <name>Jboss Repository for Maven</name>
      <url>http://repository.jboss.org/maven2&lt;/url&gt;
    </repository>
  </repositories>
  ...
</project>

And then declare the following dependencies:

<dependencies>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.3.2.GA</version>
  </dependency>
  <dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.9.0.GA</version>
  </dependency>
</dependencies>

Note the dependency on hibernate-core (http://repository.jboss.org/maven2/org/hibernate/hibernate/3.3.2.GA/ contains only a pom).

Pascal Thivent