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