-
-
Save timmolderez/92bea7cc90201cd3273a07cf21d119eb to your computer and use it in GitHub Desktop.
If you'd like to use a .jar file in your project, but it's not available in any Maven repository, | |
you can get around this by creating your own local repository. This is done as follows: | |
1 - To configure the local repository, add the following section to your pom.xml (inside the <project> tag): | |
<repositories> | |
<repository> | |
<id>in-project</id> | |
<name>In Project Repo</name> | |
<url>file://${project.basedir}/libs</url> | |
</repository> | |
</repositories> | |
2 - Let's say we want to use the file myLibrary-1.0.jar in our project. First add a dependency to your pom.xml: | |
<dependency> | |
<groupId>be.ac.vub</groupId> | |
<artifactId>myLibrary</artifactId> | |
<version>1.0</version> | |
</dependency> | |
Two things to note: | |
- You can pick whatever you like for groupId. | |
- The name of your .jar has to follow this naming convention: artifactId-version.jar | |
If needed, rename your .jar file. | |
3 - Put myLibrary-1.0.jar in the following location, relative to the root of your git repo: | |
libs/be/ac/vub/myLibrary/1.0 | |
In general, your path looks like this: repository-location/groupId/artifactId/version | |
(Just like Java packages.. if the groupId contains a ".", this corresponds to a "/" in the file structure..) | |
4 - In that location, also add a file myLibrary-1.0.pom , with the following contents: | |
<?xml version="1.0" encoding="UTF-8"?> | |
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>be.ac.vub</groupId> | |
<artifactId>myLibrary</artifactId> | |
<version>1.0</version> | |
<description>POM was created from install:install-file</description> | |
</project> | |
5 - You have now created your own local Maven repository! To test if it works, compile the project via Maven: | |
mvn clean install -U | |
(The -U is optional; it forces Maven to re-download project dependencies) | |
6 - Finally, make sure to add the .jar and .pom files to your git repository as well, so it also works via continuous integration. |
so helpful , thanks a lot , by the way i faced a warning about the jar's pom file and i created the folder structure with this command instead of manually and it work like charm
mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=mylib-1.0.jar -DgroupId=com.example -DartifactId=mylib -Dpackaging=jar -Dversion=1.0
Thank you so much!
Thanks!
I get the warning Could not validate integrity of download from file://[...]r: Checksum validation failed, no checksums available
.
@qin-liu: How exactly did you solve this problem?
thank you very much, I searched a lot ways but not work。this worked good。 and I add a notice, some version need add jar file checksum file, just checksum jar file online and add myLibrary-1.0.jar.sha1 file, copy checksum in it。to do same to pom file with myLibrary-1.0.pom.sha1
My Jar looks empty in github. And even when I clone it I can't open it inside my IDE. Can anyone help me on this
Thanks a lot!!!
Thanks That was very good !!!!!!
thank you very much, I searched a lot ways but not work。this worked good。 and I add a notice, some version need add jar file checksum file, just checksum jar file online and add myLibrary-1.0.jar.sha1 file, copy checksum in it。to do same to pom file with myLibrary-1.0.pom.sha1