English 中文(简体)
How to upload jar to respository?
原标题:

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):

问题回答

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




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签