How can i deploy artifacts to Nexus repository using java. Is there any API for this.
I had configured nexus in my local machine. I need to deploy artifacts in it using java. Is there any docs or links for this.
Asked
Active
Viewed 1,979 times
2

Carlos Landeras
- 11,025
- 11
- 56
- 82

ѕтƒ
- 3,547
- 10
- 47
- 78
-
1why do you want to deploy artifacts using java ? rather than maven – Sajan Chandran Jul 03 '13 at 11:46
-
you can still use maven through java by using the maven jar. Have a look here too: http://stackoverflow.com/questions/11674537/retrieving-maven-artifact-from-repository-using-maven-java-api – Guillaume Jul 03 '13 at 12:20
-
If you can use jenkins, there's a [post build task](http://lazylightening-tech.blogspot.com/2013/07/using-jenkins-to-deploy-artifacts-to.html) to publish artifacts to a maven repo – Alper Akture Jul 03 '13 at 17:38
2 Answers
7
WARNING: Aether is no more, the project was archived by Eclipse and handed back to the ASF. It is now known as the Maven Artifact Resolver. The example below may still be applicable.
I have used Eclipse Aether (formally Sonatype Aether) in the past:
Aether is a library for working with artifact repositories. Aether deals with the specification of local repository, remote repository, developer workspaces, artifact transports, and artifact resolution.
For example, you can deploy an artifact to a remote repository:
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact jarArtifact = new DefaultArtifact( "test", "org.eclipse.aether.examples", "", "jar", "0.1-SNAPSHOT" );
jarArtifact = jarArtifact.setFile( new File( "src/main/data/demo.jar" ) );
Artifact pomArtifact = new SubArtifact( jarArtifact, "", "pom" );
pomArtifact = pomArtifact.setFile( new File( "pom.xml" ) );
RemoteRepository distRepo =
new RemoteRepository.Builder( "org.eclipse.aether.examples", "default",
new File( "target/dist-repo" ).toURI().toString() ).build();
DeployRequest deployRequest = new DeployRequest();
deployRequest.addArtifact( jarArtifact ).addArtifact( pomArtifact );
deployRequest.setRepository( distRepo );
system.deploy( session, deployRequest );
Take a look at their example code and documentation for more information.

Jonathan
- 20,053
- 6
- 63
- 70
-
1Eclipse Aether was archived, any idea where we can still find documentation? – Gilad Baruchian Apr 10 '18 at 09:38
-
1Looks like the project was handed back to Apache – see my edit. Documentation there might be relevant, or, some archive site (e.g. wayback machine) might have a copy. – Jonathan Apr 10 '18 at 11:47
0
If you are using maven then you can use mvn deploy command to do that. Make sure you have nexus repository listed in you pom.xml or settings.xml.

Adi
- 2,364
- 1
- 17
- 23