Maven 3 - Use local repo for locally produced artifacts - java

Let's say I have an EAR that uses a 3rd party JAR from an online Maven repo, and a local JAR I produce myself, that needs to be pulled from my local repo.
If I build the EAR, it complains that it can't find the local JAR in the repo, because it's looking online. However, that is the correct behaviour for the 3rd party JAR.
How do I get Maven to look locally for artifacts, AND online? I guess it would be best to look locally as a last resort. Is there a way to do this?

You could install the .jar file to the local repository.
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
or else include the .jar as system dependency.
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies

Related

How to add custom jar files into pom.xml

I am creating a maven project, in which I've two jar's for say x and y for now,which contains some helper classes for my project. I want to added these x and y jars to my project's pom.xml as dependency. As these two jar files are not available in maven repository. So I try to use these jar in my pom.xml with in repository tag.How to achieve this. I've searched in google and found one project , which is similar to my project.
when I build this it able to build application, I saw the jar file it created.But I couldn't create the same with new project. If I copy the entire pom.xml I'm able to build.What is dependency-reduced-pox.xml and how it will create. and in moven-local folder how it creates another pom.xml, which command is used to create these auto generated xml files Can any one help me to do this. Here are the screen shots of my maven project I got it .
here are other screen shot.
There are 3 ways:
A) Install your JARs to your local Maven repository and then use them in your project with provided groupId, artifactId and version: How to add local jar files to a Maven project? (this is quick & easy & pretty clean until you remove your local repository and delete your JARs accidentally).
B) Install Nexus or Artifactory (will will be then your remote Maven repository), set it up in your settings.xml, add those JARs to remove Maven repository and download them from there (this is much less error-prone, but in longer run it's worth it).
C) not recommended: Other response (btw. currently with most upvotes) from previously suggested resource: How to add local jar files to a Maven project? which contains systemPath tag. You shouldn't use it, because it will cause lots of headaches in the future (for example if you want to package your application to WAR), it's not the correct way, but it's possible.

How to deploy 3rd party jars in maven root repository?

I have a jar file I want to upload that jar to the central maven repository for my further use. I am tried this-link and It run successfully but as I told you above now I want to upload this jar to the central for further use and I am trying to use this-link. But I am not understanding it properly. I need a brief tutorial that what is
DRepositoryId and Durl
and how can I get DRepositoryId and Durl.
If you really want to upload your jar file to maven central, you need to follow these instructions: https://maven.apache.org/repository/guide-central-repository-upload.html

For an external jar, is it necessary to add a dependency in pom.xml file with a system path if jar already present/copied to lib folder

I have downloaded ojdbc14 jar from the internet and copied it to the lib folder of my maven project. Is it necessary to add dependency in pom.xml as well. Currently working without adding.
You can use tricks to manually upload a jar into the lib folder, but it does not make sense. And it would work cause the build process will just look for that jar into the lib and if found everything will compile nicely. BUT....
Maven is a useful tool that helps you handle dependencies, internal, external, third parties, any kind, it's one of his benefits, don't need anymore to look around for jars, and put them manually into the lib dir, but why? You would override one of the basic behaviour of Maven.
Maven set lots of rules to give you the ability to manage them the way you want, you have options about how to handle every single dependency of your project, you can point to a local jar within a dependency, you can set the scope of the dependency, the type you can exclude some of the inherited transitives, and so on...
But this is the standard approach for standard situation
You should simply define the dependency, maven will downloaded from the configured repo or the default one, maven central, and retrieved from your local repo if there are no updates on that artifacts all the other time you will build that artifact.
If you have issues with licenses for ojdbc14 then the solution is configure the oracle repo where you can easily download it.

Maven dependency for self placed jars in project level

I created the java class and converted into jar files. So, I want to use those jar files which I have placed in project level in some folder like "External Jar".
So I need to write a dependency in maven that when someone imports my project they should be able to run the program.
Basically you created your own jar and you want to publish this jar, so that when somebody else clone/use your project, this jar comes with (assuming that you have a maven project and dependency of your jar is included in pom.xml).
To achieve this, you need to publish your jar to maven , you can follow many of the online docs like http://kirang89.github.io/blog/2013/01/20/uploading-your-jar-to-maven-central/ on how to publish jar to maven central.
Edit:- As suggested by khmarbaise, please use official reference http://central.sonatype.org/ for central repository.

Setting up a maven project for already made jars

I have some jar files that I need to include in my build - I'd rather not specify them as system dependencies - that creates a nightmare for setup. I have been uploading them to artifactory and then they can be pulled down directly, but I won't always have access to artifactory while building.
What I was thinking of doing is creating a project that has these jar files in them. It could be one per or all of them (open to suggestion). I was wondering if there is a graceful way to handle this?
What I have done (which is clearly a hack) have a project that takes the jar and during the compile phase it unpacks the jar into the target/classes directory. It then packs those class files back during the package phase. it essentially creates the same jar file again...massively hackey. Could I add the jar into the resource area or is there a different project type I could use? I am open to any ideas.
You may try to use install:install-file. I would go about it in the following way.
Create project that contains all your jars in some location
Configure install:install-file in pom of this project to install jars in repository in some early phase.
Make sure that this pom is executed before anything else that depend on it. List it as first module.

Categories

Resources