How to export a java maven file from eclipse with all external libraries and maven dependacies so the other peorson opening does not have to download and import the external libraries?
I tried the Archive file exporting method. But it wasn't successful, cause it lost the external libraries while importing, and it lost clases and packages .
The default local repository is located based on OS:
Windows: C:\Users<User_Name>.m2
Linux: /home/<User_Name>/.m2
Mac: /Users/<user_name>/.m2
Assuming that you want to store these dependencies in the project folder so that every user does not have to download and import the external libraries according to this source you can download all your dependencies to the target folder with the following command.
mvn install dependency:copy-dependencies
You can also specify the folder.
mvn dependency:copy-dependencies -DoutputDirectory=specific-folder/
To make use of these commands you will have to install Apache Maven Dependency Plugin
Related
So I need to connect a library to my repo in IntelliJ, so I can test the library as it interacts with my main project. And I got this command from a member on my team: "So you need to change .java files in entity manager (which is the library) repo and do mvn clean package to generate the jar file locally, the use that jar in your project repo.
Then create dummy folder in your project with the same package name and copy those .java files from entity manager."
What does change the java files mean? What about "use that jar"? I'm so confused.
Use "mvn install" instead of package. This puts the library into your local .m2 repo and makes it available to your project in idea
If you do mvn clean package it produces a .jar file in target/ folder. Use that dependency to your project if they both share a common parent pom.xml
If you do mvn clean install it produces the jar file in target/ folder + copies the .jar file to your local m2 folder. That way you can use that .jar file to any project locally. Just use the with matching version, artifact and groupId whereever you need to use that jar file.
For both options above, you need to define sth like below in your pom.xml
<dependency>
<groupId>com.my.library</groupId>
<artifactId>mylib-artifact</artifactId>
<version>1.VERSION</version>
</dependency>
Not recommended:
You can also put the .jar file to your project (without doing mvn clean install) See: http://blog.gtiwari333.com/2016/12/maven-use-local-jar-without-installing.html
Or manually add the .jar to your project as project dependency using your IDE's project configuration
I need to export executable jar from intellij spring boot project. its basic rest only. How can it possible. I have created the artifact jar and when i try to run it with java -jar xxx.jar it returns manifest file not found error.
Generally you have this error when you generate the JAR using the IDE directly (export option of Eclipse for example).
You can either use the Maven goals clean install or clean package to compile and generate the JAR in your target folder and/or local repository.
package - take the compiled code and package it in its distributable
format, such as a JAR.
install - install the package into the local repository, for use as a
dependency in other projects locally
The install will execute the package one step before install it on your local repository.
Maven Lifecycle Documentation
If you have installed maven, On the terminal of Intellij Idea use following code.
mvn clean package
Your Jar will be saved inside "target" folder inside the project directory
I have a .java file that makes use of JSON library, it imports the library's package:
However the package isn't recognised, so I tried to add the library to my project:
But it didn't work:
My library is located inside Root/libs/LibraryFolder1/LibraryFolder2/.java files and .classe files and .jar file
I tried importing both .jar and .java and library as a whole (by clicking on the root folder). Neither worked.
EDIT: I've also tried running a command:
mvn install:install-file -Dfile=C:\xampp\tomcat\webapps\Root\libs\LibraryFolder1\LibraryFolder2\Craps.jar -DgroupId=org.json -DartifactId=json -Dpackaging=jar -Dversion=20150912 -DgeneratePom=true
which gives a BUILD SUCCESS result, but doesn't seem to change anything.
Since you are using Maven as your dependency (aka libraries) management, you cannot add it in your ide and expect it to work. It will be overriten to what you have in your POM file when you synchronize the project. Moreover, if you would make this to work from IDE, compilation would fail on CLI so bye bye every auto build tools.
To make this work, you mas add your local JAR to your local Maven repository and include it trough POM file.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
After you install your Craps.jar as Maven artifact, include it in dependencies section in POM file.
I have a a java class looking for another project using an import.
import this.is.the.java.file.im.looking.for
I run off a pom.xml file using a maven build in eclipse and it's working fine using the m2e plugin. When i try to run it on jenkins using the maven integration plugin it says it can't find the file because it's looking into the same project folder instead of the dependency project.
Maven configured on jenkins also requires appropriate settings.xml to fetch dependencies it required. There might be possibility that due to inappropriate settings.xml file , maven won't be able to fetch dependencies.
Please make sure settings.xml at in jenkins installation directory e.g. /var/lib/jenkins for ubuntu.
also check whether settings.xml under .m2 folder in your jenkins installation directory.
and finally validate whether there is jar file fetched in local maven repository under .m2 directory.
I need to release our Maven build Java project to an remote QA team. For this I would like to download all the dependencies, and send them so they do not need to download them.
Currently all dependencies are defined in the pom.xml file, and we use either mvn install or mvn package to build the project. Some of the project members use uber jars, others use jars + dependencies to do execution.
What would be the easiest way to pre-package the dependent jar files so that there is no download from the internet, and does not change our current build process too much?
A possible solution would be to purge your local repository, tell Maven to download every dependencies and plugin dependencies of your project and make a ZIP of that.
To purge your local repository, you can simply delete the folder {user.home}/.m2/repository. Then, you can use the dependency:go-offline goal:
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
mvn dependency:go-offline
This will download everything that your project depends on and will make sure that on a later build, nothing will be downloaded.
Then, you can simply make a ZIP of {user.home}/.m2/repository and send that to your Q/A team. They will need to unzip it inside their own {user.home}/.m2/repository to be able to build the project.
Offline Package deploy
Your requirement can be accomplished by creating a stand alone jar file with full dependencies. You can port it anywhere please refer https://stackoverflow.com/a/35359756/5678086
Build a full dependency JAR file as said in the answer
Copy the JAR to the destination machine you want
Run the below command from there
mvn install:install-file -Dfile=<path-to-file>
This will install the dependecies in the maven repository of the destination machine. This is fully offline
Theoretically if you know which maven commands you'll use (package, install, etc.) you could clear out your ~/.m2/repository folder, run those commands once on somebody's dev box, then distribute the repository folder. You can run maven -o install etc. to have it not give annoying warnings. This might be a slightly smaller distro than the go-offline answer.