tags:

views:

135

answers:

5

Greetings,

Can anyone tell me how the heck I'm meant to use a maven repository or whatever the term is with a project?

I've downloaded the OAuth library from Google. I run mvn compile, test, install, deploy

I want to know where the Jar goes so I can just put it into my class path. Any help appreciated!

+6  A: 

The jar exists within the $MAVEN_PROJECT/target folder.

A copy also gets put into your local repository at $HOME/.m2/repository.

Jason Nichols
A: 

If you are using maven to build your project, you just have to add the jar as a dependency in your POM.xml. maven will automatically look in the local (.m2/repository) repository for all dependencies. If it doesnt find it, it tries downloading from central (maven's default online rep) or any other repository you have specified. You wouldnt need to add anything to classpath.

vinny
A: 

Should be under your HOME_DIRECTORY/.m2/repository. Look at the settings.xml file under .m2 folder. There should be a tag like this:

<localRepository>${user.home}/.m2/repository</localRepository>

That says where the jars get stored. HTH

CoolBeans
A: 

(assuming you mean "where do i put the oath library?") It appears that that project has a repository already. you can stick this in a repositories section in your project's pom.xml.

james
+7  A: 

Can anyone tell me how the heck I'm meant to use a maven repository or whatever the term is with a project? I've downloaded the OAuth library from Google (...) I want to know where the Jar goes so I can just put it into my class path. Any help appreciated!

Basically, what you need to do with Maven to "put a library on the class path" is to declare this library as a dependency of a Maven project. Let's see how to do this and how to get started here.

First, you need to create a Maven project (i.e. a directory containing a pom.xml used to describe your project and following a given structure). Maven provides a tool that can create a project for you, you just have to run the following command (where the artifactId is the name of your project):

mvn archetype:generate -DgroupId=com.stackoverflow -DartifactId=Q2722892 -Dversion=1.0-SNAPSHOT -DinteractiveMode=false

Then cd in to the project directory and edit the pom.xml to declare the oauth repository (Maven has a central remote repository called central which is known by default but oauth is not available in central so you need to tell Maven where to find it):

<project>
  ...
  <repositories>
    <repository>
      <id>oauth.googlecode.com</id>
      <url>http://oauth.googlecode.com/svn/code/maven&lt;/url&gt;
    </repository>
  </repositories>
</project>

Now you can declare a dependency on the aouth artifact (or whatever artifact you want to get from the oauth repository):

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>net.oauth.core</groupId>
      <artifactId>oauth</artifactId>
      <version>20090825</version>
    </dependency>
    ...
  </dependencies>
</project>

Now you can use the oauth library in the code under src/main/java, the oauth library is on the class path.

To build your project, run install (this will do a bit more than compiling, running tests, packaging but this is my recommendation):

mvn install

And find the jar of your project under the target directory.

To be honest, this particular example is not the easiest one to get started with Maven because it requires to understand several concepts that can't be covered in a single answer and I would warmly recommend to check Maven by Example for a good introduction of Maven before to go further.

Pascal Thivent
Thanks - don't like Maven! I can appreciate why it might be useful for some. I rather just dump my JAR's into one directory. Curse Apache :)
steve
@steve Hmm... what about don't use Maven then? :?
Pascal Thivent
Droids (And Mahout) seem to be using it. I'm sure this is something that will grow on me! Can you please add this to your answer - <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>im.jeanfrancois.App</mainClass> </manifest> </archive> </configuration> </plugin> </plugins></build>
steve