Add several local Jars as Maven dependencies [duplicate] - java

This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 6 years ago.
I have 50 jars that I need to add to a Maven project as dependencies. They are not in the public repository, I cannot install a local repository and I'd like to know a quick solution to add them in my pom.xml.
I know that to add a local dependency you could write
<dependency>
<groupId>sample</groupId>
<artifactId>com.sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
but this is simply a real long task with several Jars. Is there an easy way to do it?
The solutions suggested in How to add local jar files in maven project? are specific for a single or few Jars but not the case when you many of them.

Add those jars to your local maven repository and then add their dependency to your POM. See this link: MKYong: How to include custom library into maven local repository?

Related

Cannot find Dependcies (from http://download.java.net/maven/2) [duplicate]

This question already has an answer here:
Maven package issue locally?
(1 answer)
Closed 2 years ago.
I run mvn clean package -U
And i get this error message below?
Could not resolve dependencies for project DD2480-Group-15:gs-maven:jar:0.1.0: Could not find artifact com.fasterxml.jackson.core:jackson-databind:jar:3.6 in java.net2 (http://download.java.net/maven/2)
And i have this dependcies in my pom.xml file?
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.1</version>
</dependency>
Is jackson deprecreated or?
I have just checked this out.
I removed that dependency from local repo and used maven to refresh the dependencies. It came without any problem. It is not the dependency the problem but the remote repo that you try to get it from.
The repository at http://download.java.net/maven/2 is deprecated, and has been replaced with https://maven.java.net/content/groups/public/
To replace your remote repository
A) If you use your downloaded version of maven then
you must find where your maven folder in your laptop exists. Then under conf/settings.xml you can configure your settings.xml
Then under mirror tag you can configure your remote repository
How to configure mirrors in maven
B) If you use a bundled version of INTELIJ for Maven then check this image of how you can configure your remote repositories

How to troubleshoot maven dependency classes not found [duplicate]

This question already has answers here:
"cannot find symbol" error in maven
(5 answers)
Closed 4 years ago.
I am trying to package a SpringBoot project of mine to use as a library in another. I had it working somewhat but not I can't get my library classes to resolve at all.
I don't get any errors to do with the dependency in my POM file. I simply can't get to my library in my code.
I am building my package then installing it in my local Maven repo with mvn install:install-file -Dfile=myPackage.jar When I navigate to my local repo, the package is there and the pom file looks right. I bring it in to my project with
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>mylib</artifactId>
<version>0.0.1</version>
</dependency>
which all matches the POM for the package in the maven repo. I update the project configuration and no issues are found in my project POM. But com.mygroup.mylib is simply not found.
It seems that Maven is finding the dependency but for some reason the classes can't be found within it.
What are some ways to get more information about where the disconnect is?
I am using spring boot 2.0.0 and VSCode 1.20.1.
Run maven command for logs to find out actual issue.
mvn clean install -X

Does Maven package dependencies by default? [duplicate]

This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 5 years ago.
I have a Maven project with certain set of dependencies. One of the dependencies is:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.0</version>
</dependency>
As long as I work in Eclipse, all is good. But when I package and try to use the resulting jar file(from command line if that matters), I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/NativeLibrary
while this class is definitely accessible in IDE.
My guess is that Maven is not packaging project's dependencies by default but in that case why don't I get more error messages complaining about more classes that were not found?
Maven will only create a jar for your project/component. This does not include the external jars (dependencies). If you want/need to include the contents of the dependencies in your jar, you should create a fat jar or uber jar. For an uber jar, you may use shade plugin.

How to use a local maven snapshot of another local project [duplicate]

This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 5 years ago.
I feel like I must be lacking some very very basic Maven knowledge here. I have a (couple of) maven project(s) and a shared library. This library should be a separate maven project with its own life cycle. I'm trying to import the library into my project using:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>nl.whatever.com</groupid>
<artifactId>my_shared_library</artifactId>
<version>1.0-SNAPSHOT</groupid>
</dependency>
...
</dependencies>
</dependencyManagement>
But maven keeps looking in my repro instead of trying to find my local build. And worst of all, it keeps looking for a jar. I get:
Could not resolve dependencies for project my.project:ejb:1.0-SNAPSHOT: Could not find artifact nl.whatever.com:my_shared_library:jar:1.0-SNAPSHOT
What's my rookie mistake? Yes, I did do a clean install of my library project.
edit:
My .m2 directory has a settings file redirecting my local repro to
/ws/repro, which contains:
/ws/repro/nl/whatever/com/my_shared_library/1.0-SNAPSHOT/
my_shared_project-1.0-SNAPSHOT.jar.lastUpdate
my_shared_project-1.0-SNAPSHOT.pom
and some property files.
edit2:
I don't think it's a duplicate. I looked at the question linked before posting my question. There is no non-maven project or external jar involved here.
Your local repository is usually in .m2/repository below the user repository. If You do clean install on your library project, it should be installed into this repository (in nl/whatever/com/my_shared_library/...). Then you can use it from all other Maven projects on the same computer.
It is furthermore important that the <packaging> is correct, i.e. the packaging needs to match the artifact you want to build. If the packaging is pom then you only create a pom (like a parent pom or a bom). Leaving out the packaging tag implictely means that you use packaging jar.
You shall try updating your pom.xml with a tag named as repositories.
Maven repositories are the places that hold build artifacts and dependencies of varying types.
A sample maven remote repository tag with its values is:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
To configure multiple repositories you can follow the guide and make use of profile in settings.xml as well.
On a side note, unless following a hierarchy or making use of specific versions of a library. You should use <dependencies> instead of <dependencyManagement>, take a look at the differences between dependencymanagement and dependencies in maven.

import external jar in maven project without creating a dependency [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Maven: add a dependency to a jar by relative path
I need import a .jar file using only a buildpath in a java maven project without creating a dependency. Can this be done?
You mean that your jar is used only to compile but is not a transitive dependency?
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
provided:
This scope is only available on the compilation and test classpath, and is not transitive.
See more on dependency scopes

Categories