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
Related
In my project I need to reference to the package installed by Maven to local repository. I've added the dependency to pom.xml, but the project doesn't want to build as it wouldn't even see the package. Here's the pom.xml fragment with dependencies:
<dependencies>
...
<dependency>
<groupId>libraryweb</groupId>
<artifactId>classes</artifactId>
<version>1.0SNAPSHOT</version>
</dependency>
</dependencies>
When I try to import the package "libraryweb" I get
Cannot resolve symbol 'libraryweb'
error. What can I do to use the package?
Edit: Intellij prompts me classes from the package when I try to use them, but I still get "cannot resolve symbol" error.
Note that groupIds and package names are not necessarily the same.
So while your JAR is installed under a certain groupId, artifactId and version, the actual package that you need to import in your Java code may have a different name.
In doubt, unpack the JAR and look at the directory structure.
I solved the problem by linking the .jar file with IntelliJ projects settings instead of using Maven to do it.
I'm a relative Maven novice and am having difficulties using a locally stored jar as a module within my IntelliJ project - a project I have taken from an online tutorial.
I've brought it into my .m2 folder using:
mvn install:install-file "-Dfile=C:/../resources/myshop-automatedtestscore 3.1.17-SNAPSHOT.jar" "-DpomFile=C:/../resources/myshop-automatedtestscore-3.1.17-SNAPSHOT.pom --Dsources=C:/../myshop-automatedtestscore-3.1.17-SNAPSHOT-sources.jar"
.jar is located at:
C:\Users\daveb\.m2\repository\com\myshop\automatedtests\myshop-automatedtestscore\3.1.7-SNAPSHOT\3.1.17-SNAPSHOT.jar
And I added the dependency in the main pom.xml as follows:
<dependency>
<groupId>com.myshop.automatedtests</groupId>
<artifactId>myshop-automatedtestscore</artifactId>
<version>3.1.17-SNAPSHOT</version>
</dependency>
When I go to Project Structure -> Libraries, I can see the Sources dependency jar file is there in grey so should be fine. However the core project seems to be unable to access the class versions of the file. In Target folder they remain .class but in External libraries they are .java
Apologies if this is a novice or obvious solution. I'm trying to resolve.
You have to install jar using below command -
mvn install:install-file -Dfile= -DgroupId= -DartifactId= -Dversion= -Dpackaging=
You have to give artifacts and other parameters so that you will be able to use in pom file using below code -
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>1.1.GA</version>
</dependency>
After that you have to complie your project so that this dependency will be added in your project.
mvn eclipse:eclipse
mvn clean install
You can press here to force refresh the plugins in Intelij.
Here you can check which repository you have and also which maven you have.
Click on preferences
Another option you have is to perform this :
mvn clean install -U
If your dependency is
<groupId>com.me.example</groupId>
<artifactId>my-example</artifactId>
<version>1.1.0</version>
Then your jar file would be my-example-1.1.0.jar and it will be under \.m2\repository\com\me\example\my-example\1.1.0\my-example-1.1.0.jar.
In your case, your jar file is myshop-automatedtestscore-3.1.17-SNAPSHOT.jar and it should be under
C:\Users\daveb.m2\repository\com\myshop\automatedtests\myshop-automatedtestscore\3.1.17-SNAPSHOT\myshop-automatedtestscore-3.1.17-SNAPSHOT.jar.
After this, do a Maven > Reimport from IntelliJ.
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
I have imported a Maven Project in Eclipse (EE Developer) and I have in my pom.xml file the following error, “Missing artifact com.oracle:ojdbc7:jar:12.1.0.2″ in this code:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
I have done so by downloading the ojdbc7.jar and run this command:
mvn install:install-file -Dfile=/Path-to-jar/ojdbc7.jar
-DgroupId=com.oracle
-DartifactId=ojdbc7
-Dversion=12.1.0.2
-Dpackaging=jar
-DgeneratePom=true
After that, I got as an output BUILD SUCCESS, and if I go to the .m2 folder I see in the com->oracle->ojdbc7 two files called “ojdbc7-12.1.0.1.jar.lastUpdated” and “ojdbc7-12.1.0.1.pom.lastUpdated” but still Eclipse brings me the code into the pom.xml file as an error?!?!?!
Can some one help?
This artifact version (12.1.0.2) has been removed to an another dependency.
See: https://mvnrepository.com/artifact/com.oracle/ojdbc7
Try to change the new dependency:
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>
After successfully running the "mvn install" command right click your Project -> Maven -> Update Project (or Alt+F5).
I would get rid of those 2 files manually (lastUpdated) then re-run your install command and finally build your project. Those 2 files have been created by mvn as flags to avoid refetching them for a certain amount of time. They certainly have been created prior to your manual install-file command.
I recommend you to follow the instruction given in this link.
"http://javabycode.com/build-tools/maven/add-oracle-jdbc-driver-maven.html"
As per your dependency in pom.xml there should be 4 files generated inside "m2repo\com\oracle\ojdbc7\12.1.0.2" folder.
ojdbc7-12.1.0.2.jar
ojdbc7-12.1.0.2.jar.lastUpdated
ojdbc7-12.1.0.2.pom
ojdbc7-12.1.0.2.pom.lastUpdated
But as you are saying you checked for "ojdbc7-12.1.0.1.jar.lastUpdated", that should not be the case. I recommend you to delete your dependency folder and then start from scratch.
Some how the jar is not getting downloaded into the local pc. I opened the maven site https://mvnrepository.com/artifact/com.oracle/ojdbc7/12.1.0.2 and downloaded the required jar and placed it in to the .m2 folder, and the error is gone.
I have a local jar being imported into my project through Maven. When I update the jar in my other project, then do maven package, it is not getting updated in the main project.
I have tried everything, cleaning it, forcing dependencies, relaunching IntelliJ, deleting m2 repository, everything. Nothing is working for me.
Any help would be appreciated.
Heres the code from the main project's pom.
<dependency>
<groupId>com.example</groupId>
<artifactId>manager</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
EDIT: SOLUTION!
I accidentally had another import of the same project in my dependencies, this time not from maven. Removed that and everything was fixed.
Thanks for everybody's help!
Your changes needs to be installed into local repository with mvn install to be visible in other project. But you can import second project as module into Intellij. After this two projects can work without install (internal syncing).
Documentation: Creating and importing Maven projects