How do I get OAuth's java client library with maven? - 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>

Related

selenium-central-framework in pom.xml

I am not able to find any hint about the issue that I am facing and hence posting my question here. Please apologize if it is something silly.
I have some working experience in selenium webdriver. However in my new project, I was asked to use an existing Selenium framework.
In the pom.xml, I am seeing the below dependency (I have edited xxx to avoid displaying the company name)
<dependencies>
<dependency>
<groupId>com.xxxqa.selenium</groupId>
<artifactId>selenium-central-framework</artifactId>
<version>2.0.18</version>
</dependency>
Question :
I couldn't understand from where that dependancy was taken from ?
Solution Tried :
I have tried searching in the maven repository still couldn't find
anything related to "selenium-central-framework"
I have checked the dependencies of selenium RC, but they seems to be different from the one that is present above.
I have researched whether any local jars were used and were linked
as dependancy. However I understand from maven repository, local
repositories will be linked with the tag "systemPath"
<dependency>
<groupId>ldapjdk</groupId>
<artifactId>ldapjdk</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\ldapjdk.jar</systemPath>
</dependency>
</dependencies>
Note that the depedency used in my project doesn't have the tag "systemPath".
Is there anyway the external repositories could be added without mentioning systemPath ??
Please help, what could be that dependency ? How to find more information about it. Thanks a ton for your help.
I suggest you one of these approaches:
Jar file
If you have access to the jar file called : selenium-central-framework-2.0.18.jar, open a command line pointing to the folder of this jar and execute:
mvn install:install-file \
-Dfile=selenium-central-framework-2.0.18.jar \
-DgroupId=com.xxxqa.selenium \
-DartifactId=selenium-central-framework \
-Dversion=2.0.18 -Dpackaging=jar
Source code file
If you have the source code of : selenium-central-framework-2.0.18.jar, open a command line pointing to the folder of this source code and execute:
mvn clean install
After one of these approaches, selenium-central-framework-2.0.18.jar will be available in you local maven repository ($HOME/.m2) and your other java maven projects will be ready to use it as dependency:
<dependency>
<groupId>com.xxxqa.selenium</groupId>
<artifactId>selenium-central-framework</artifactId>
<version>2.0.18</version>
</dependency>
This is a workaround if you don't have a server to host an artifact repository management server like :
https://www.sonatype.com/nexus-repository-sonatype
https://www.jfrog.com/confluence/display/RTF/Maven+Repository
Explanation
Almost all free, public, safe, useful and cool java libraries are hosted in https://mvnrepository.com . So any person in the world can use it in their maven project with this piece in their pom.xml:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
But in some cases, publish your source code to https://mvnrepository.com is not an option:
Oracle Driver. This driver (.jar) can only be downloaded from the official Oracle page. Private source code like IBM, Microsfot,etc
Source code of your company that should not be public.
Some super cool library that is only in github but not in the maven central repository.
So in this cases, the best and scalable solution is host and configure some artifact repository management server like :
https://www.sonatype.com/nexus-repository-sonatype
https://www.jfrog.com/confluence/display/RTF/Maven+Repository
This platforms are an emulation of https://mvnrepository.com . So with a minimal configuration:
You can host your special or private jars
Your maven projects could use this jars with the standrad xml dependency in pom.xml.
If you don't have a server to implement one of these platforms, the previous approaches could help you and get the same results

How to import classes from `com.android.build.api.transform` package in Maven

I am trying to transfer a gradle-based build plugin for android to a maven build system.
Up to now I was successful except with the android part.
It seems that I am missing classes from the package com.android.build.api.transform. Although I used this code
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle</artifactId>
<version>2.2.0</version>
<type>jar</type>
</dependency>
which is supposed to provide (rather indirectly) the required classes/packages, it seems that this is not working.
I also added
<repositories>
<repository>
<id>android</id>
<name>android</name>
<url>https://plugins.gradle.org/m2/</url>
</repository>
</repositories>
just in case, with no luck. Still the project is not able to compile due to missing classes.
Any idea what I am missing? I am very new to the gradle/maven scene, and I still feel out of my waters with these tools.
For reference here is a link to the javadoc of this artifact.
Thanks for your help
The 'gradle' artifact does not contain the missing package. As you mention, it depends transitively on at least one artifact that contains that package, but only in scope 'runtime'. Hence, it will not be available to your project on the compile classpath.
Anyway, adding the dependency explicitly in your pom.xml is the right thing to do. A search for the missing package on search.maven.org shows that you have the choice between com.android.tools.build:transform-api and com.android.tools.build:gradle-api. Locking at the transform-api artifact reveals that it's deprecated and encourages to use gradle-api instead. (The latest version is '2.0.0-deprecated-use-gradle-api'). I downloaded the gradle-api jar file, which indeed has the missing package. So please try adding that artifact to your pom.xml instead:
<dependency>
<groupId>com.android.tools.build</groupId>
<artifactId>gradle-api</artifactId>
<version>2.3.0</version>
</dependency>
I didn't check version 2.2.0, but if you for some reason want to use the older version, it will probably work too.
the transform API was a Google's Android Gradle plugin technology. but it was absorbed into and expanded by Gradle. so newer Android plugins migrated to the Gradle API and they no longer include the transform engine, which now is part of Gradle. if you use the deprecated transform API from Google that was bundled with older plugins, you will get the engine. but what you plan to do about all the other dependencies on Gradle, i have no idea.

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

Including QRGen in pom.xml

I'm developing app in spring + hibernate in maven and I need to make QR codes so
I've found this tutorial http://viralpatel.net/blogs/create-qr-codes-java-servlet-qr-code-java/
In that tutorial following libs are in use:
xzing and qrgen (net.glxn.qrgen)
I've added in pom.xml dependency on xzing and its running but qrgen needs his own repo so
I've included repository like on that page: http://kenglxn.github.com/QRGen/ :
but it seems that http://kenglxn.github.com/QRGen/repository is down
Anyone knows new (or exact) repo address or could tell me what I'm doing wrong
version 1.2 is now available from maven central http://search.maven.org/#artifactdetails%7Cnet.glxn%7Cqrgen%7C1.2%7Cjar
please use:
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId>
<version>1.2</version>
</dependency>
Basically you have a third party JAR that is not available in a (public) repository. Best would be if you had a company wide repository that you use as proxy. It is quite easy to set up Nexus for this task. Then you can import the JAR to that repository (e.g. Nexus has a default "3rd party library" repository setting). If you don't have such a repository you need to import the JAR to your local repository but this restricts successfull builds to your machine - obviously not what you want when you use Maven. See here for the syntax for a local import.
Of course you could set up a network drive as a company wide repo, some think this is easier than setting up Nexus or any other repo server. Trust me, it is not worth it, do it the right way from the beginning.

install JAR from remote repo (clojar)

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

Resources