install JAR from remote repo (clojar) - maven

I want to download and install this Clojure library but cannot for the life of me figure it out. I researched Maven, but couldn't get it to find the repo. How can I easily install a Clojure library onto my machine?

You could add the repository containing this jar to your pom or settings file and specify the relevant jar as a dependency.
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
...
<dependency>
<groupId>clj-http</groupId>
<artifactId>clj-http</artifactId>
<version>0.4.1</version>
</dependency>

download https://clojars.org/repo/clj-http/clj-http/0.4.1/clj-http-0.4.1.jar
mvn install:install-file -DgroupId=clj-http -DartifactId=clj-http -Dversion=0.4.1 -Dpackaging=jar -Dfile=clj-http-0.4.1.jar

If you are using Leiningen you can just read all about how to connect to repository server on a recent Sonatype blog post from Tim O'Brien.
If you are using Maven you should get a repo server like Nexus and setup the clojure repo as another proxy repository and add it to your public group.
If neither of these approaches is ok with you you can use Raghurams approach or number23_cn. Both of them however are semi optimal and will not scale for teams or many artifacts..

Related

How can I add maven artifact into an existing maven project

How can I add maven artifact into an existing maven project.I understand that I can build a jar locally and use file: protocol but this is possible using maven also.
For example I have a basic maven project
https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project and the artifact:
<repositories>
<repository>
<id>myrepo.org</id>
<name>MyRepository</name>
<url>http://mywork.com/repository</url>
</repository>
</repositories>
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
I tried adding the code above to the project pom.xml fails because dependency is not in central maven repo.
mvn clean install
I then tried editing my settings.xml by adding the tag, that also failed because dependency was not found.
Im overlooking something pretty basic here.
Maven works on the concept of local and remote repositories.
The local repository refers to a copy on your own installation that is a cache of the remote downloads, and also contains the temporary build artifacts that you have not yet released.
Remote repository is repository you access the artifacts via file or http / ftp protocols , it can be an internal repo or a remote public hosted.
When you add dependency maven search that artifact in local if not found then remote repo will be searched. Still not found then error is reported.
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
In your case, 'ethereumj-core' can not be located neither of location, you need find this jar and do a manual install to local repo.
mvn install:install-file -Dfile=< folder >\ethereumj-core.1.1.0-RELEASE.jar -DgroupId=org.ethereum
-DartifactId=ethereumj-core -Dversion=1.1.0-RELEASE -Dpackaging=jar
once properly installed maven should be able find this artifact when you add this as dependency to any of the projects (in pom.xml).
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
</dependency>

WebLogic client jar

I want to use Java with JMX to monitor WebLogic. I need to use wlclient.jar which is provided into WebLogic lib directory.
Is there any maven repository which I can use to download the wlclient.jar?
The only way that I found is to manually import the jar file into my repository but this is not a option for me.
Another alternative is to create an in-project repository. This makes your project truly portable. This method is similar to the 'Use Dependency with system scope' mentioned by A. Di Matteo, except that it has the added benefit of being able to use any scope (and not just 'system').
I had the same issue as you, using a jar which was not available in Maven Central and after exploring all of the possible options, I settled on the in-project repository which I believe is better that system-scoping a dependency since it frees you to choose the scope.
Steps to do this:
Create a sub-directory called 'lib' in your project
Add this lib as a repository in your pom
<repositories>
<repository>
<id>lib</id>
<name>In Project Repo</name>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
Install the artefact to your lib directory:
mvn install:install-file -Dfile=myArtifact.jar -DgroupId=x.y.z -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true
And, finally use the dependency like you would use any other dependency
<dependencies>
....
<dependency>
<groupId>x.y.z</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</dependency>
</dependencies>
If you can't find the jar in any Maven repository, you could apply any of the following actions, depending on your needs:
Internal Maven Repository
If you don't have an internal repository (like Artifactory or Nexus), normally used in companies as internal maven cache/proxy/point-of-control, but could also be an option to install it and run it locally.
You could then upload the library there, providing Maven GAV (GroupId, ArtifactId, Version) and make Maven pointing to it as a repository (for your, for your CI server if any, for your colleagues if any). You can then add the library as standard maven dependency.
This solution has longer set-up, but better maintainability.
Install the library in local cache
You could use the Maven Install Plugin and install the library to your local cache, as shown by this official example.
Basically, you could run the following command:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to\wlclient.jar -DgroupId=weblogic -DartifactId=wlclient -Dversion=1.0.0 -Dpackaging=jar
It will copy the library to your local Maven cache with standard Maven GAV. However, as above, you should make sure to replicate the same set up on any CI server and any team mate machine as well. You can then add the library as standard maven dependency.
This solution has quicker set-up, but lower maintainability though.
Both solutions however affect the portability of your build (build would fail if someone tries to build it outside of your company network or team).
Use dependency with system scope
You can have the jar as part of your project and point at it via the system scope for that dependency.
<dependency>
<groupId>weblogic</groupId>
<artifactId>wlclient</artifactId>
<version>1.0.0</version>
<systemPath>${basedir}/path/to/library/wlclient-1.0.0.jar</systemPath>
<scope>system</scope>
</dependency>
You should rename the jar though in order to be compliant with Maven conventions.
This solution is more portable, requires much less set-up, but again it needs to be maintained and requires a check-in of the concerned library as part of your versioned project (some may strongly disagree on this practice).

How to store jars in github based maven repo

Ive setup a github repo to store custom archetypes, and I can start a new project off these archetypes (on separate vm) using something like
mvn archetype:generate -Dcatalog=https://raw.github.etc./archetype-catalog.xml
now i'm trying to store some 3rd party jars remotely in the same repo and reference them from a pom.xml as dependancies
First I installed the jar locally with
mvn install:install-file ..params..
the repo structure I have goes like:
https://github.com/myappco/myrepo
|
|___releases
| |
(group id)adobe.flex.messaging (ie. adobe/flex/messaging)
common
1.0
(common-1.0.jar)
* trying to make this work
|___snapshots
|
(group id)com.acme.archetypes (ie. com/acme/archetypes)
my-archetype
1.0-SNAPSHOT
* archetype resolved ok
archetype-catalog.xml
The settings in my project:
<dependency>
<groupId>adobe.flex.messaging</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<repositories>
<repository>
<id>orb-snapshots</id>
<url>https://github.com/myappco/myrepo/releases</url>
</repository>
</repositories>
I think I must be doing something dumb, because I can archetype:generate from the github repo archetype-catalog.xml. Can anyone see what I messed up?
Ta
You need to deploy your artifacts in github using mvn deploy. You would need to have set up github appropriately - perhaps similar to what is mentioned in Hosting Maven Repos on Github.

How do I get OAuth's java client library with maven?

I'm trying to follow this guide here http://www.ibm.com/developerworks/web/library/wa-oauthsupport/index.html which gives information on how to use the OAuth client library provided by OAuth and HTTPClient 4 to authenticate your connection. I am working on a Java Swing CLIENT, NOT a OAuth PROVIDER.
OAuth provides a client library here on this page http://oauth.net/code/
I'm talking about the one marked by "A Java library and examples were contributed by John Kristian, Praveen Alavilli and Dirk Balfanz." which points to an SVN repository http://oauth.googlecode.com/svn/code/java/core/
I do not understand how to incorporate this library into my Eclipse project. I would like to just be able to add a maven dependency because it's so clean and works so well. I don't see coordinates readily available, and when I look at http://oauth.googlecode.com/svn/code/java/pom.xml I see the following coordinates but they don't work when I run the Maven build with the coordinates, and I get a "Missing artifact net.oauth:oauth-parent:jar:20100601" error in Eclipse's integrated Maven 3 pom.xml manager. I thought the entire point of Mavenizing a project was so that you could use its coordinates to pull it in.
<dependency>
<groupId>net.oauth</groupId>
<artifactId>oauth-parent</artifactId>
<version>20100601</version>
<packaging>pom</packaging>
</dependency>
I've tried the follow dependency after snooping around on the maven repository, and it didn't have all the classes/interfaces/etc I needed.
<dependency>
<groupId>net.oauth.core</groupId>
<artifactId>oauth</artifactId>
<version>20100527</version>
</dependency>
Is this the wrong way to incorporate this project? Is it not truly mavenized in a way that makes it easy to share? If I can't use Maven, what's the best path to follow to include this library into my project?
This is a bit of a repeat of How to include oauth library in Eclipse? but that question doesn't address the Maven aspect of it at all.
The OAUth libs doesn't seem to be available in Maven Central, so you have to add the following repository either to your settings.xml or to your pom.xml:
<repository>
<id>oauth</id>
<name>OAuth Repository</name>
<url>http://oauth.googlecode.com/svn/code/maven</url>
</repository>
I actually found the way to make it work with exactly your version of oauth-parent:
Create a directory and enter it:
mkdir oauth && cd oauth
Checkout code for your version:
svn co http://oauth.googlecode.com/svn/code/java/
Enter checked out directory (java), compile and deploy jars yourself:
cd java && mvn source:jar install
After that your dependency will work:
<dependency>
<groupId>net.oauth</groupId>
<artifactId>oauth-parent</artifactId>
<version>20100601</version>
<packaging>pom</packaging>
</dependency>

Maven Thrift repository

Does anyone know if the Thrift libraries are in any Maven repository?
0.6.1 artifacts now available from main apache repo (http://repo1.maven.org/maven2)
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.6.1</version>
</dependency>
https://issues.apache.org/jira/browse/THRIFT-363
I'm not sure what the Thrift libraries are (next time, maybe add a link) but according to Maven Browser, there is a thrift artifact in the scala-tools repository:
<repositories>
<repository>
<id>scala-tools</id>
<url>http://scala-tools.org/repo-releases/</url>
</repository>
</repositories>
Update: I can't say much about the version (and the content) hosted in the scala-tools repository but this is very likely an artifact made available by the scala folks for their own needs. Actually, the Apache Thrift project is using Ivy and publishing the java library to a maven repository (it will be the Apache snapshots repository, see THRIFT-363) is something on which they didn't work until recently. But the issue is closed now and my understanding is that they will publish an artifact with the next release.
As of now there are not any available, you will have to include the jar in your local repository.
You can set up something like Artefactory, a local repository and add the libthrift.jar there.
http://mvnrepository.com/artifact/org.apache.thrift/libthrift
You can search Maven repository from there.

Resources