How to load/add third party jar files to bitbucket? - java

I want to load some jar file that are not present in maven repository or any other such repository.
For that I have created a repository named as "maven-repo" on bitbucket and cloned it to my local machine.
Now I am using command
mvn install:install-file -DgroupId=groupid -DartifactId=myid
-Dversion=5.1 -Dfile=/path to file/filename.jar -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository -DcreateChecksum=true
After that I push that folder/repository to bitbucket server.
Now I want to add it to my maven project's pom.xml.
I added like:
<repository>
<id>Hyperv </id>
<url>https://myurl/repository/</url>
</repository>
But it gives me error failed to load a jar.
How to include a jar file and import classes in project???

Deploying with Maven
From official documentation (I cannot link, this is a popup)
Bintray adds a new layer to traditional Maven repositories in the form of a package.
A package acts as container for managing metadata about your project and its versions and may contain a collections of artifacts with different group ids.
When uploading files to a repository, you can associate them with specific package and version information in various ways:
Deploying to this repository
Please go into a specific package in this repository to see how to set up Maven to deploy artifacts to that package.
In Maven’s setting.xml file, add the following section to declare your Bintray credentials. Use your API key as your password (not your login password, please!):
<server>
<id>bintray-user-package-package</id>
<username>user</username>
<password>**********</password>
</server>
Add the the following Distribution Management section to your project’s pom.xml file to tell Maven to deploy into this package using the credentials you configured in the previous step:
<distributionManagement>
<repository>
<id>bintray-user-repo-package</id>
<name>user-repo-package</name>
<url>https://api.bintray.com/maven/user/repo/package</url>
</repository>
</distributionManagement>
Manual deploy
Prepare artifact folder as is described in How Do I Upload My Stuff to Bintray?
And deploy using commannd like this
mvn deploy:deploy-file -DpomFile=myfile-0.1.pom -Dfile=myfile-0.1.jar -DrepositoryId=bintray -Durl=https://api.bintray.com/maven/user/repo/package
In general deploying with maven is much easier

Related

mvn package ignoring repository in pom.xml

We cannot get a project to pull from a remote repository using mvn package. In maven installed folder, config/settings.xml we declare our internal central repo:
<mirrors>
<mirror>
<id>advnexus</id>
<mirrorOf>*</mirrorOf>
<url>http://internalserver/nexus/content/groups/public</url>
</mirror>
</mirrors>
This works for all of the jar files hosted at this repo. But we have some additional jar files we pushed to a server under our control and running Sonatype Nexus. So in the project's pom.xml, we setup our remote repo as:
<repositories>
<repository>
<id>companynamenexus</id>
<name>Company Name Project Repo</name>
<url>http://nexus.companyname.com:8081/repository/project-name</url>
<layout>default</layout>
<spanshots>
<enabled>false</enabled>
</spanshots>
</repository>
</repositories>
When I run the build, it pulls any needed jar files from the main repo, but simply times out trying to pull the jar files that don't exist on this repo vs. using the repository in the pom.xml.
Note that in the settings.xml mirror section, I tried changing the <mirrorOf> to be central vs. *, but this just caused additional errors.
I have also tried setting up this repo as a secondary mirror in the settings.xml, tried commenting out the mirror in the settings.xml and place it as an additional repository in the pom.xml, all without finding the right combination. Seems like a simple problem, but the answer is eluding us.
Best solution: Don't try to access two different internal Nexus, but set up a repository group in one of the Nexus that contains all other repositories (may they be hosted or proxy, internal or external). Then you can simply set a mirror entry on that repository group and you are fine.
Second best solution: Change your mirror entry to <mirrorOf>*,!companynamenexus</mirrorOf> and define the additional repository in the <repositories> section of your settings.xml.

What's the correct way to generate a .pom file from my pom.xml?

I've been learning how to publish a Java library to jcenter. jcenter/bintray wants me to upload the following artifacts:
Binaries: {groupId}/{artifactId}-{version}.jar
Source: {groupId}/{artifactId}-{version}-sources.jar
(Optionally) Javadoc: {groupId}/{artifactId}-{version}-javadoc.jar
POM: {groupId}/{artifactId}-{version}.pom
I can generate the first three no problem (binaries with a standard mvn package and sources and javadoc using the plugins described here).
Currently I'm just manually copying my pom.xml to {groupId}/{artifactId}-{version}.pom and that works fine, but it smells. I'm sure there must be an automated Maven way of doing this but I can't find it. Can anyone help?
You can upload your Maven project directly to Bintray just by adding some code to your pom.xml and then running the appropriate mvn command:
First add a distribution section to your maven and specify the URL from which to distribute your project:
<distributionManagement>
<repository>
<id>bintray-repo-maven-example</id>
<url>https://api.bintray.com/maven/tamarjfrog/maven-repo/maven-example/;publish=1</url>
</repository>
</distributionManagement>
In order to work with Bintray you need to provide your Bintray username and API Key as upload credentials in the username and password tags of your Maven settings.xml file. The API Key can be found when editing your Bintray profile page:
<server>
<id>bintray-repo-maven-example</id>
<username>tamarjfrog</username>
<password>***my-top-secret-api-key***</password>
</server>
the you just run this simple command:
mvn deploy
The project will be built, uploaded to the the Bintray repository target URL you provided, and published. For more information take a look here.
mvn deploy should automatically push your pom

Jenkins : Add custom jar in maven project

I am trying to add custom jar which is not available in Maven repository. When I am executing in local I am pointing to the Jar path, So no issues. But when I execute with Jenkins I am facing issue as Could not resolve dependencies for project. Also it list down the two Jar file missing which I added custom.
So help me how to add the custom Jar wile executing using Jenkins. Also I am using Nexus for binary storage. After Jenkins executes successfully the image file will be posted to the nexus directory with versioning.
You have 2 options
1) If your have access to the local Nexus/Artifactory repo that your Jenkins uses you can add the jar to that repository and it will be downloaded as normal.
2) You can have a local repository where you check the jar into SCM under your project. You would then access it like this in your pom. See http://doduck.com/adding-local-jar-in-maven-local-repository/
<repositories>
<repository>
<id>localrepository</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>

How to import a deployed jar "SNAPSHOT" from local Artifactory repository into another project?

I am a newbie in Artifactory, I have 2 projects one depends on another...
I set up Artifactory on a server and deploy the first jar into libs-snapshot....and change the C:\Users.m2\setting.xml and add this tag in the pom of the deployed project:
<distributionManagement>
<snapshotRepository>
<id>serverId</id>
<name>serverName</name>
<url>serverUrl/artifactory/libs-snapshot/</url>
</snapshotRepository>
</distributionManagement>
how can I access the first project from the second one via Artifactory repository
I am working on Netbean8.2, glassfish 4 and artifactory 4
By default, maven doesn't know to look anywhere except your local repo and maven central. You'll need to tell it the additional repos it can look in either via a pom setting or settings.xml.
You can see some example and additional details in the Maven docs.

How to configure Maven2 to publish to Artifactory?

Currently I have a Maven2 project that builds a JAR when you run:
mvn clean package
I need to now tweak the pom.xml to publish this JAR (myapp.jar) to an Artifactory server running at:
http://myartifactory/artifactory/simple/myorg/myapp/0.1
I tried adding a <repositories> element to my pom.xml but nothing is being published with this config:
<repositories>
<repository>
<id>myartifactory</id>
<url>http://myartifactory/artifactory/simple/</url>
</repository>
</repositories>
Any ideas as to how I could get publishing to work? For simplicity's sake, pretend that this Artifactory repo is authenticated to accept publishes/writes from a user with a username=foo and password=bar.
You have two options (please note that the later is the recommended one):
Add DistributionManagement part to your pom and server part to your settings.xml
Let's say you want to deploy to libs-snapshot-local repository. In this case you need to go to the tree browser in Artifactory, focus on the repository level, copy the Distribution Management snippet and paste it in your pom.xml:
Next, you need to tell maven the credentials. For that, click on your username in the top right corner, enter your password to unlock the screen, copy the server tag from Maven Settings panel:
This one you paste in your settings.xml. Don't forget to replace the ${server-id} with the real server id (the one you have in Distribution Management now).
Now, just run mvn deploy and enjoy.
Working with Maven Artifactory Plugin:
Add the relevant <plugin> part as described in the wiki to your pom.xml. It includes both the target repository and the credentials (please use external credentials source, like environment variables or system properties).
Run mvn deploy and enjoy not only the deployment to Artifactory, but also additional features as described below.
Additional features of Artifactory Maven Plugin (on top of regular Maven deployment):
Allow adding custom properties to the deployed files
Provide the build bill of materials (the buildInfo), allowing Build Integration with any build server (even those not supported by JFrog) or even with standalone builds (without build server at all).

Categories

Resources