How to install third party source and javadoc JARs? - maven-2

Is there way to install third party source and javadoc JARs by using maven?

Guide to installing 3rd party JARs
If you want to use the feature mentioned there about version 2.5 of the maven-install-plugin (if the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default by maven-install-plugin:2.5), then you can run:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-fi‌​le -Dfile=<path-to-jar-file>
To generate the jars for the javadoc and the sources use e.g.:
Maven Deploy Plugin
Maven Javadoc plugin
Maven Source plugin
If you want to install a secondary artifact (such as the sources jar) for an already installed jar, then follow the step described here: Installing Secondary Artifacts

For info specifically about how to install 3rd party javadoc JARs see: How to deploy Javadoc jar file.

There are atleast three approaches in which 3rd party JARs can be added to Maven projects.
Install manually using mvn install command
Adding the location of jar file in pom dependency with the the following tag system
Creating a 'dummy' maven repository pointing to jar location.
I will focus on third approach which I find more cleaner and does not require any mvn command and works out of box from any IDE.
Step 1: Add the location of local 'dummy' repository in pom.xml
<repositories>
<repository>
<id>repo</id>
<name>repo</name>
<url>file:${project.basedir}/src/main/resources/lib</url>
</repository>
</repositories>
Here the 'dummy' repository location is the 'lib' folder of my project directory
Step 2 : Add the jar dependency into your pom.xml
<dependency>
<groupId>com.cloudera.impala</groupId>
<artifactId>impala-frontend</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
choose any groupId but make sure that artifactId and version is of the format <artifactId>-<version>.jar ( Name of 3rd party jar)
Step 3 : Create the folder structure as per the groupId,artifactId and version mentioned in the Step 2 in your local 'dummy' repository. So in this case the folder struction would be /src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/
Place your jar in the version folder and build your project.
You will get the following output which treats your 'dummy' repository to be the provider of your 3rd party jar.
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.pom
[WARNING] The POM for com.cloudera.impala:impala-frontend:jar:0.1-SNAPSHOT is missing, no dependency information available
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[WARNING] Could not validate integrity of download from file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar: Checksum validation failed, no checksums available
[WARNING] Checksum validation failed, no checksums available from repo for file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[INFO] Downloaded from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar (7.0 MB at 79 MB/s)
[INFO]

Related

How to deploy pom.xml as SNAPSHOT with maven?

I have a pom.xml and i want to use it as the parent pom.xml of my project.
and want to make the name for the pom.xml which was uploaded on Nexus like ABC-root-pom-2.0.0-SNAPSHOT.pom
so could anyone tell me what the command is using maven ?
Thanks
Do not worry about what name the pom will have on the repository manager. The Maven repository format dictates that.
To get a Maven project with pom packaging deployed you have to do the normal steps of adding the distributionManagment to the pom and the credentials to the settings.xml. Then you run
mvn clean deploy
and thats it. Your other project can then reference it. An example for such a pom project is my progressive-organization-pom.

How can I view transitive dependencies of a Maven pom.xml file?

Is there a CLI tool I can use to quickly view the transitive dependencies of a Maven pom.xml file?
On the CLI, use mvn dependency:tree
(Here are some additional Usage notes)
When running dependency:tree on multi-module maven project, use mvn compile dependency:tree instead1.
Otherwise, the POM Editor in M2Eclipse (Maven integration for Eclipse) is very good, and it includes a hierarchical dependency view.
1If you don't compile, you might get error Failed to execute goal on project baseproject: Could not resolve dependencies for project com.company:childproject:jar:1.0.0: Could not find artifact. This might happen because dependency:tree command doesn't build projects and doesn't resolve dependencies, and your projects are not installed in maven repository.

jar-with-dependencies Maven Assembly

I created a simple Maven project (Packaging type - Jar) that has dependencies on Spring and My Sql library (mysql-connector). When I package this project with $mvn package I do get a jar file after successful execution of this command.
I was also trying to include all the dependencies in the output jar file, so I added a 'jar-with-dependencies' assembly descriptor, but as the documentation says:
The `jar-with-dependencies` descriptor builds a JAR archive with the contents of the main project jar along with the unpacked contents of all the project’s runtime dependencies.
I want to include the dependencies in JAR form, not the unpacked way. How can I do this?
Java cannot load classes from jars in your jar out of the box. You must configure it with project like one-jar and maven plugin.
Maybe this can help Maven Shade Plugin:Maven Excecutable Jar
Olivier
Vicky is trying to aggregate the jars and this is known as "building-an-aggregate-jar" in Maven's terms. You can find more in Robert's[1] and Artifact Technical Notes'[2] blog.
One discussion[3] that can help as well.
Regards
[1] http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/
[2] http://blog.artifact-software.com/tech/?p=121
[3] http://maven.40175.n5.nabble.com/Aggregate-POM-for-thirdparty-package-dependencies-not-downloaded-td113927.html

Why i always gets the [INFO] Unable to find resource in repository?

greetings all
I am using maven 2 in my spring project
and when I try to build the project from the terminal using the commands (mvn clean-mvn install)
it cannot download any dependency from any of the repos, and I always gets Info like :
Downloading: http://repo1.maven.org/maven2/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository first (http://repo1.maven.org/maven2)
Downloading: http://mirrors.ibiblio.org/pub/mirrors/maven2//velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository second (http://mirrors.ibiblio.org/pub/mirrors/maven2/)
Downloading: http://repository.jboss.com/maven2//velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository jboss (http://repository.jboss.com/maven2/)
Downloading: http://maven.jahia.org/maven2/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository additional (http://maven.jahia.org/maven2)
Downloading: http://208.79.234.53:8081/artifactory/libs-releases-local/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[WARNING] Unable to get resource 'velocity-tools:velocity-tools-generic:pom:1.4' from repository host.varaza.com (http://208.79.234.53:8081/artifactory/libs-releases-local): Error transferring file: Connection timed out
any ideas, why such thing occurs ?
From the repository link, it looks like this dependency does not have an associated pom file. This is the reason for the warning.
Typically, dependencies in the repository also have a pom file, which describes the project, as well as specifies its dependencies. Maven first downloads this pom file, so that it can resolve transitive dependencies, if any.
Maven is just trying to get the pom files from your repositories and will try for as long as it can't download them.
This is happening most probably because the libraries (dependencies) you reference don't have a pom file in any of the remote repositories available. This is probably normal.
However if you want to get rid of the message you could deploy minimal pom files for those dependencies in your company's repository. You can choose to just install them locally but then other developers in your team would still have those messages.
Maven can't reach the sites where dependencies are located.
Try running
ping repo1.maven.org
or opening it in your web browser. Maybe you should set the firewall to allow Maven downloading stuff from internet.
I used the following dependency - works for me.
<dependency>
<groupId>velocity-tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>1.4</version>
</dependency>

Forcing Maven2 to download source jars to local repository

I have my company dependencies (including non-FOSS third party stuff) in a Nexus repository, including source jars (downloaded with mvn dependency:resolve), where available.
I would like to have the source jars (and javadoc jars) download to my local repository (~/.m2/repository) so that I can go "offline".
I tried various combinations of mvn dependency:resolve dependency:go-offline -Dclassifier=sources, but it does not seem to copy them to my local repository.
Thanks.
Did you try:
mvn dependency:sources