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.
Related
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 am working on a Maven project and I am using eclipse as an editor. I clone a project from GIT and then create a git repository in eclipse , import it and then create a maven project. After i finished the project of setup i got a lot of errors and this is due to pom.xml file and I am missing about 300 artifacts.I know want to know how can i find and add those artifacts in my project. I have seen different answers for that and one of the answers is to upload maven project. I did it but still not working , I am still missing the artifacts.
I really need some help here since i want to start working on this project as soon as possible.
Maven pulls all the dependencies either from maven repository or from local repository automatically (typically C:/Users/user1/.m2 on windows). if there are lot of dependencies, eclipse takes a while to download them all.
check if you see building workspace at the right bottom corner of eclipse. you can press Alt+F5 to refresh the project and then try command mvn clean install from your root folder (where your pom.xml is placed)
Sometimes, jars are not available on maven repository such as sqljdbc. in that case you will have to manually install them to your local repo using below command if you have the .jar file
mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar
or a quick and dirty approach would be copy the .m2/repository folder from previous machine if project was working good on that machine.
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.
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.