2

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.

E.S.
  • 2,733
  • 6
  • 36
  • 71
  • If you get ClassNotFound exception, this is not from a dependency that wasn't downloaded. I might be though from a dependency that was downloaded, but doesn't contain the classes it should, as described by @StuPointerException – Jens Schauder Apr 28 '15 at 18:48

3 Answers3

4

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.

npe
  • 15,395
  • 1
  • 56
  • 55
  • Great! That worked in downloading all those hundreds of .jar files! But now I need to include them all in my eclipse build. Is there a quick way to do that? The standard way of adding .Jar libraries into eclipse is one by one. – E.S. Apr 28 '15 at 19:34
  • Updated the answer with description of generating eclipse project files. – npe Apr 28 '15 at 19:39
  • For `M2_REPO` do you just add that value to the `Linked Resources` section of Eclipse? If so... it didn't seem to work, though I just used the target directory created after the `mvn clean install` and `mvn dependency:copy-dependencies` --- I'm seeing locations like this `M2_REPO/org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar` I'm not sure where the `/org/slf4j.../` parts come from since all the dependencies are in the `target\dependency` directory. – E.S. Apr 28 '15 at 20:24
  • Okay I actually had to make a `M2_REPO_2` variable as I couldn't change the original. I did end up updating the paths and now it runs! Thanks a lot!! – E.S. Apr 28 '15 at 20:33
  • By the way, with the `mvn dependency...` calls, is there a way to ensure the source code is compiled with the `.class` files, or at the very least the javadoc? – E.S. Apr 28 '15 at 20:48
  • If you declare a dependency in `pom.xml`, the jar file containg `.class` files is downloaded and used as a classpath for compiling your `.java` files. If you want to download sources and javadoc artifacts as well, you may need to declare them explicitely in `pom.xml` or when using `mvn eclipse:ecplise`. See [here](http://stackoverflow.com/a/97168/1344008). – npe Apr 28 '15 at 20:51
  • Also, try this: `mvn dependency:copy-dependencies -Dclassifier=javadoc`. That should download javadoc for your dependencies. – npe Apr 28 '15 at 20:57
1

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/

StuPointerException
  • 7,117
  • 5
  • 29
  • 54
1

Use dependency plugin go-offline task.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69