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?
Related
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
What I want to do is downloading one jar (foo.jar) and all dependencies of it into lib/ directory
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get \
-DremoteRepositories=http://nexus.example.com/content/groups/public/ \
-Dartifact=com.example:foo:1.0-SNAPSHOT \
-Ddest=/path/to/foo.jar
I also used -Dtransitive=true to download the transitive dependencies but it seems not working. I used copy-dependencies instead of get but it requires the current directory containing pom.xml namely a maven project here.
You can download everything online from this site https://jar-download.com/online-maven-download-tool.php. This works for me.
How does my firm get a jar into a maven repo so maven projects can access it from inhouse.
Can someone please point me to a good step by step details on how to do the following
Make a jar with Maven
Get the jar installed into a local maven repo
I doubt your company wants their private internal code hosted on a public repository:
Install your own repository server inside your own network, I use Archiva. This is the most ideal solution, then you can set up Mavenized projects to automatically upload themselves to your private repository when you do mvn:release and everyone will see the new versions. How to use Archiva is all very well documented.
If they have open source code that want to share, that is different:
You can publish public facing open source code through Sonatype.
If you just want to install a dependency to a local repository:
If you just want to install a .jar locally that is easy and well documented.
mvn install:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar
I'm using the following command to create a local repository within my project (used on many systems so I was experimenting a bit with having a local maven repository inside my project folder for storing external jars that can't be found on any online repository):
C:\Users\someone\workspace\someProject>mvn install:install-file
-Dfile=somePackage-1.0.0.jar
-DgroupId=foo.bar
-DartifactId=somePackage
-Dversion=1.0.0
-Dpackaging=jar
-DlocalRepositoryPath=libs
-DcreateChecksum=true
This is run from Windows command line. Somehow, even with -DlocalRepositoryPath, it's still installing the jar into the default local repository (C:\Users\someone\.m2\, etc.). What am I doing wrong here? I tried different variations of the libs path, like /libs, /libs/, full path, using "", but nothing worked. Why isn't the -DlocalRepositoryPath argument not working here? I'm using Maven 2.2.1.
The install:install-file option ignores the localRepositoryPath when using the version 2.2 of the plugin. However, it works with version 2.3 and higher.
Also, try using the fully qualified name of the plugin to specify the version:
mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \
-Dfile=<path-to-your-file> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
I have jar files that cannot be found on Maven Central repository. I would like to add the jar so I can just include extra tag in my pom.xml file and other developer can use the jar. What are the steps needed to upload the jar to http webserver webfolder? What file should I uploaded beside custom.jar? What other files need to exist on the webfolder side by side with custom.jar?
If you already have a web server set up pointing on a web folder, a simple way to deploy your custom JAR would to use the deploy:deploy-file Mojo. As documented in the Usage page of the Maven Deploy Plugin:
The deploy:deploy-file mojo is used
primarily for deploying artifacts to
which were not built by Maven. The
project's development team may or may
not provide a POM for the artifact,
and in some cases you may want to
deploy the artifact to an internal
remote repository. The deploy-file
mojo provides functionality covering
all of these use cases, and offers a
wide range of configurability for
generating a POM on-the-fly.
Additionally, you can specify what
layout your repository uses. The full
usage statement of the deploy-file
mojo can be described as:
mvn deploy:deploy-file -Durl=file://C:\m2-repo \
-DrepositoryId=some.id \
-Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=test] \
[-DgeneratePom=true] \
[-DgeneratePom.description="My Project Description"] \
[-DrepositoryLayout=legacy] \
[-DuniqueVersion=false]
Only the 3 first parameters are mandatory (short version). If you wonder what the repositoryId is, the documentation of the Mojo says:
Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication. Default value is: remote-repository.
In other words, the simplest way to use this would be to copy your custom JAR on the machine hosting the web server and to use the file:// protocol when specifying the URL. There is no additional setup required. If you want to deploy remotely, then scp:// is often the preferred protocol (there are others but this one is pretty easy to setup). Below, an example using scp:
mvn deploy:deploy-file -DgroupId=my.group -DartifactId=myartifact -Dversion=1.0 \
-DgeneratePom=true \
-Dpackaging=jar \
-Dfile=custom.jar \
-DrepositoryId=some.id \
-Durl=scp://REMOTEMACHINE/PATH/TO/WEB_ROOT/maven2_repository
Actually, using a web server to host your own Maven repository is perfectly fine but it can be a bit painful to initialize. One solution to solve this issue is to use a Maven proxy (like Nexus for example) instead of just a Maven repository. But this goes beyond your question.
For more resources on this, check (the principles are still valid even if the implementation solutions are a bit outdated):
Using Maven in a corporate environment
Creating the repositories
Nexus Book: Repository Management with Nexus
Preferably, you would need a local maven repository. One option for this is Nexus
Or if you are working just yourself, you can save the overhead and put the jars in the repository on your machine - under home/.m2/repository, in an appropriate folder
Next command helps to install the jar to the local repository. After this you can upload folder with the jar from local to the remote repository.
mvn install:install-file \
-DgroupId=com.name \
-DartifactId=aaaa-bc \
-Dversion=1.0 \
-Dpackaging=jar \
-Dfile=aaaa-bc.jar \
-DcreateChecksum=true