How to troubleshoot maven dependency classes not found [duplicate] - java

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

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

Why maven build is failing with error: "package com.microsoft.jdbc.sqlserver does not exist"? [duplicate]

This question already has answers here:
How to connect sql server through java code?
(3 answers)
Closed 4 years ago.
I have created project want to deploy it using Jenkins and Git. I created maven project and added all the dependencies required.
My one of class contains following code-
try {
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
} catch(Exception e) {
System.out.println("Problem registering JDBC driver");
}
and indicates error at com.microsoft.jdbc.sqlserver.SQLServerDriver() this line like not able to find com.microsoft package.
I have added maven dependency for Microsoft server driver in POM file-
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>test</scope>
</dependency>
Now when i try to run that project with clean install it gives error as:
package com.microsoft.jdbc.sqlserver does not exist
and fails the build.
What should I do to remove this error and run my project successfully?
You include the artifact with <scope>test</scope> but apparently use it in the main code.
Change the scope to compile or (if scope of this artifact is not managed elsewhere) simply remove <scope>test</scope>.
For the future, what helps with this kind of questions is to simply run:
mvn dependency:tree -Dscope=compile
You will see a tree of artifacts considered for the compilation.

Importing a 3rd party jar on Maven and IntelliJ IDEA

I know there are tons of questions and answers about this problem, but none of them helped.
I have a jar, which I would like to import to my local java project.
I have created the project on IntelliJ IDEA with Spring Initializer.
I have used this command to install the jar into ~/.m2 repo
mvn install:install-file -Dfile=C:/Users/xxxx/Desktop/xxxx/lib/mylib-1.2.11.jar /
-DgroupId=com.test.custom -DartifactId=mylib -Dversion=1.2.11 -Dpackaging=jar
Then I have added these lines into my pom.xml file
<dependency>
<groupId>com.test.custom</groupId>
<artifactId>mylib</artifactId>
<version>1.2.11</version>
</dependency>
I have no errors, everything seems in order.
However, when I want to import a class from that jar.
import com.ca.bla.bla.MyClass
I receive an error called "Cannot resolve symbol "MyClass".
How can I solve it?
I have tried to create a lib folder and copy the jar in it and add it as a module
I have tried to create a localrepo for maven
They all gave me the same result...
Thanks in advance

Add several local Jars as Maven dependencies [duplicate]

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?

How to build a Java Maven project without internet [duplicate]

This question already has answers here:
How do I configure Maven for offline development?
(15 answers)
Closed 7 years ago.
I'm trying to convert a java project into a Maven project with the Eclipse plugin. However my work environment does not allow any internet connection whatsoever and I cannot compile the code outside of the work environment. I have listed all the Referenced Libraries (which im guessing are the dependency libs) in the original Java project which I was hoping Maven would take from rather than connecting to the internet. Is there a way I can build the Maven project without connecting to the internet>
You need an internet connection. Maven isn't initially self-sufficient. It needs to download a bunch of plugins along with their dependencies and the dependencies of your own project. And this really depends on what sort of settings you have for your projects. One set up will require one set of dependencies, another - a whole different one. You can't download artifacts from the Maven Central manually and then install them locally one by one. Simply put, that sounds stupid.
I understand that you're coming from the Ant world where Ant has everything it needs on the local file system. However, Maven relies on the fact that it will have a central repository (either Maven Central, or your own repository - Nexus, Artifactory, etc.) from which to download the plugins and dependencies it needs. There is no point in you migrating to Maven, unless you'll be allowed access to the Central Maven Repository.
Yes, indeed, you can run Maven offline and you can have Maven produce a local repository for you to use when you are in offline mode. However, what you're trying to do is against Maven's principles.
If your company won't allow access to Maven Central, just stick to Ant. Your effort will be a waste of your company's and, ultimately, your own time.
you can add every jar to maven repository using mvn install command, then use dependency for only added jar. if you use plugins you need do some works for them..you use maven for 1 time with internet then use -o to use maven offline(mvn -o install).
mvn install:install-file -DgroupId=com.example -DartifactId=example -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
<dependency>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
</dependency>

Categories