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.
Related
Coming from npm/yarn background, for each and every project we will have node_modules which holds all the dependencies and libraries, if we wish to reset our project from clean state, we can always delete the entire node_modules and reinstall the libraries.
rm -rf node_modules/ && yarn cache clean && yarn install
Now trying to learn Java and trying out Maven, correct me if I'm wrong, we define the dependencies on pom.xml, which essentially the same as package.json on yarn/npm, and the downloaded dependencies will be stored on /target?
Is /target equals to node_modules and hence I can actually delete entire /target and restart the downloading process?
The dependencies are not stored in target, but in .m2/repository in your user directory. This is the so-called local repository. It also holds all artifacts build on that computer/account.
You can delete it if necessary and only lose your local builds.
The target directory, on the other hand, gathers the (intermediate and final) results of a build. It can also be deleted, usually by using mvn clean.
you can re-install the maven dependencies using the following command:
mvn dependency:purge-local-repository
there is no node_modles equivalent for maven, there is a central local repository maintained .m2/repository folder in per system.
Maven first search for the dependency in that local repo if not found then goes to maven central.
So if you want to delete your local cashed repository you can just simply delete all the folders in .m2/repository folder.
Then maven will not found the dependencies locally and will go for outside which is maven central.
And target contains the build artifact for each project. And
mvn clean install
command will execute the two lifecycle phases clean and install. To run install, maven will run all the phases preceding install in the default maven lifecycle.
For further reference .
build life cycle
You can delete the .m2 folder lying in the below location somewhat
and then do update maven project.You can also do (Force update of snapshots/releases").See this answer -here
Edit-As JF suggested ,the folder also contains the settings.xml ,A file that contains global settings for all maven executions,which you might not want to delete ,so you can just remove the repository folder,and reinstall your dependencies.
Unix/Mac OS X – ~/.m2/repository
Windows – C:\Users\{your-username}\.m2\repository
I'm still fairly new with Maven but I believe this will explain what your asking.
When you set up your local repository for files/packages that are downloaded based on your POM dependencies they will be stored there and not in your 'target' folder.
The target folder is used to house all of your java files as well as the dependency files you specified in your pom but these are copies from your 'repository' folder that is setup on your local box.
When you run clean on your machine it will remove all the files in the 'target' folder. Your originally downloaded dependencies will remain in the 'repository' directory that you setup.
I am currently building out some projects using an aggregate pom. It calls out some parent poms that build out the artifacts.
The artifacts build out ok.
What I would like is to capture the generated jar files and place them into a directory as they are created build after build, version after version.
Possible?
Thank you!
Without knowing more about why you want to achieve this, it's hard to recommend a solution.
A mvn clean install will install all the artifacts into your local repository, but assuming you want a more custom directory layout - you could use the maven-antrun-plugin and use ant to arrange the relevant files.
If you're happy with the default repository layout, you could also configure the repository settings for the project to deploy your plugin into a specific filesystem location (which would be dedicated to this particular project).
Alternatively, you could use the wagon plugin to do the deployment:
http://www.java-tutorial.ch/maven/deploying-in-file-system-using-maven
im using a .bat file that runs
cd dir
mvn clean install
copy dir\*.jar %LIFERAY_TOMCAT_HOME%"\..\deploy
what do you think? would that suit your needs?
I work behind a very massive firewall that likes to hiccup on random connections, which makes all work with remote repositories a living nightmare for me!
I am looking to work with a project from Git (this one https://github.com/mrniko/netty-socketio) which heavily utilizes maven for downloading dependencies.
What I would like to do is on another terminal (such as http://cloud9.io or something) download all the maven dependencies so that the entire project can be run standalone.
I have already tried mvn clean install and then zipping up the source folder, but its actually not enough! I still get ClassNotFound related errors when I try to run the project locally in eclipse. And for the record, I did add the compiled *.class files in the build properties, so Eclipse knows where they are. It seems like there are some random classes that get generated dynamically which still aren't present (such as log4j -- and I really don't want to hunt each one down individually)
I am wondering if there is a fully thorough way to download all possible dependencies from maven and then either run a project 100% standalone, or create a local maven server from it?
I am running Java 7 on Eclipse Luna and I do have Maven installed on my windows 7 machine (though again it barely works on remote repositories). I also have a Cloud9 instance which I could use to run Maven commands, then zip up the results for local download.
When you execute mvn clean install, maven downloads all dependencies of currently built project to your local maven repository. This is usually located in
%USERPROFILE%\.m2\repository
When you build your project, maven uses that path, to lookup required dependencies.
If you want do download them all, you can try using mvn dependency:copy-dependencies. Then, you'll find all project dependencies intarget/dependencies directory of your project. This also includes transitive dependencies.
To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin. Using that plugin, you can generate eclipse .project and .classpath files, using mvn eclipse:eclipse command. This will populate eclipse files with required dependencies from maven. You should then import the project to eclipse using Import existing projects into workspace, instead of Import existing maven projects.
maven-eclipse-plugin will add all those jars relative to a folder specified by M2_REPO variable. Just make sure you edit this variable inside eclipse project properties, and you should be set.
I've had to deal with similar issues. I would find that due to changes in firewall policies, occasionally all the .jar files in my project had been updated to be a 1K file that, when opened within notepad++ contained a message from the firewall saying that the download had been blocked.
I recommend looking into Nexus for your local repository management, it means your local projects don't have to go past your firewalls to check for maven updates.
http://www.andrejkoelewijn.com/blog/2010/03/09/getting-started-with-nexus-maven-repository-manager/
Use dependency plugin go-offline task.
the question is:
i start a local lib to collect some common utils in it.
then i use eclipse m2e to run as Maven Install, and it truely generate the jar into my local cached repos dir.
and now, i want to use that lib as a dependency in my project, i just type the dependency xml as the other (like spring etc.).
but it just can load that lib in the maven dependencies libs.
I search the web and find that systemPath could work, but i don' t like this way. how can i use my local jar in a same way?
Install it into your repository. Either local (mvn install) or run repository software like Artifactory, Archiva or Nexus. http://maven.apache.org/repository-management.html
You can do a (non-Maven) build and:
install the JAR in your local "repo" directory,
manually upload it your group / corporate repository, or
install it in a so-called "internal repository" that you manage by hand: see http://maven.apache.org/guides/introduction/introduction-to-repositories.html.
(I have even resorted to using an "internal repository" that was part of the project's version control check-out; i.e. putting the JAR into version control.)
But I think that the best approach would be to Mavenize the build for the utility JAR, and handle it just like your main Maven projects.
Use goal install-file .
Like , mvn install-file.
I want to build my project with Maven. How do I do that?
Maven is installed,
the project is called Sertsu1
it contains a pom.xml-file
What must be entered in the command line to start building?
If your project is organized as Maven expects, e.g. your source code is in the src\main\java directory you can run
mvn package
to just build your jar
mvn install
to install it in your local Maven repository
mvn clean
to remove a previous build
Beware that you won't go very far with Maven without reading about it. You can start with this book.
In order to create an artifact (jar-file) you need to invoke
mvn package
This is very basic and you should take your time to read the suggested manuals before using maven.
Navigate to the folder that contains the pom.xml and enter
mvn package
(for a quick result)
Your machine needs to be connected to the internet as maven will download a lot of files from public repositories.