I have created spring-boot project in VS Code with maven. I am going to use oracle.jdbc.driver.OracleDriver to connect to oracle database. In Intellij Idea,
with right click on the jar I used to click add as library and it was done.
In visual studio code I have added path to ojdbc8.jar in .classpath as shown in this github issue, But I get Caused by: java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver again.
In a maven project, all the dependencies are handled by pom.xml. We can use either maven repositories to download the dependencies or you can add it from your local directory. The following can be done install jar to local maven repository.
mvn install:install-file \
-Dfile=<path-to-file> \
-DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<packaging> \
-DgeneratePom=true
Reference - http://maven.apache.org/general.html#importing-jars
Related
As jitpack.io has been down for almost two days now, I am trying to migrate the jars to different repository.
I took the local jars of the required libraries and deployed them with mvn deployfile:
mvn deploy:deploy-file \
-DgroupId=com.github.dmurph \
-DartifactId=jgoogleanalyticstracker \
-Dversion=69f68caf8e \
-Dpackaging=jar \
-Dfile=jgoogleanalyticstracker-master-69f68caf8e-1.jar \
-Durl=https://gitlab.com/api/v4/projects/{your-project-id}/packages/maven \
-DrepositoryId=gitlab-maven
This is great and I can see the jars being deployed and I can link to them.
However it seems that any dependencies for the original library are ignored and when trying to use this I am getting a lot of Class not found exceptions of the related dependencies.
Is there a way to publish the jar with correct links to dependencies?
I have a local jar which I need to test. This jar has not yet been pushed to maven repository.
I created a sample project and added this jar as an external jar on the classpath by clicking on configure build path.
When I import the class from the jar eclipse is able to import it but when i run Maven build it gives an error saying
com.x.y package does not exist
ClassName.class cannot find symbol
What is going wrong over here ?
Just push it to your local maven repository, this is the command line:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Later add this dependency in your pom and it will work.
Is there any way to install an arbitrary Maven artifact into your local repository without first creating and switching to a project and specifying that package as one of its dependencies?
Yes, if you have the jar file of the artifact that you want to install to your local repository, you can the run the below command from your command prompt or terminal. Replace the value inside the angle brackets to your desired ones. And then you can use this as a dependency in your Maven projects.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
HTH
I am Trying to add a third party jar to jenkis .m2 repository
This is the command i found to add it to the repository from command line
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
i have a linux machine where jenkins run by its own user. it has a .m2 repository in the home directory. when i tried the above command it gives error saying that, The program 'mvn' can be found in the following packages:* maven * maven2 . so jenkins can build with out a maven installed?, if so how it is done?. how can i add the jar to .m2 repository without installing maven ?
i read that maven need a setting.xml file in its .m2 folder, but i cant find any for jenkins.
You can also use the maven binary from the jenkin's maven-plugin. Use find / -type f -name mvn to find out, where the jenkins maven plugin is installed to and call mvn from there.
You can then change mvn install:install-file ... to <pathFromFind>/mvn install:install-file ... or add this path to your PATH variable.
I added a jar with:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
And added it as a dependency. M2eclipse went through the external repository URLs attempting to download the jar and failed. When and how will it check the local repository for the jar?
Resolved: don't mix up underscores and hyphens.
Go to your user directory i.e. C:\Profiles\youruser there should be a folder called .m2 may be hidden. Inside you can see whether that jar has been installed or not(although if the console says BUILD success you should be good).