1

I've been looking at a web application project that uses a combination of Ivy during development and a set of shell scripts to manually launches the app using the java executable at runtime and by specifying a hard coded class path. Coming mostly from a .NET/NuGet background and having some experience with some other packages managers such as NPM, Ruby Gems, Rust cargo, I'm wondering where the same command line tools are for Java. I've been using java -jar ivy.jar but that only seems to resolve/install the dependencies globally, what about building, running, and eventually publishing the application?

Besides tools I'm also wondering if manually tweaking classpath is regular business in Java or if there are best practices for setting up dependencies in a more graph oriented fashion like other dependency managers. I feel like I'm missing some obvious solution here but my searches on the topic are not turning up anything reassuring. Ultimately I would like a reasonable solution that is formulated with code/configuration so that any developer can pick it up and so that it can be run completely outside of eclipse if needed.

jpierson
  • 16,435
  • 14
  • 105
  • 149
  • 2
    You'd normally use Ivy with Ant (instead of shell scripts), and the better alternative would be to replace both with Maven. Maybe [this question](http://stackoverflow.com/questions/15561322/maven-or-ivy-which-one-is-better-with-a-system-already-in-production-and-the-o) will be interesting for you. – Fred Porciúncula Oct 09 '15 at 19:27
  • 1
    Maven is de facto standard. – lexicore Oct 09 '15 at 19:45
  • 1
    Maven is indeed a sort of standard, but nowadays Gradle is catching up as a no-xml no-nonsense alternative. Both are awesome in their own way. – Gimby Oct 09 '15 at 19:48
  • Thank you Yvette. I've reworded the question a bit. Originally I was trying to be general in order not to reveal private information which I realize non may have come across is a "what tool is the best?" type of question. I'm interested in all solutions to redundant configuration and requiring a Eclipse to build. – jpierson Oct 14 '15 at 23:23

2 Answers2

3

Have you looked at Maven in your searches?

It fills the package management aspect as well as some others like, build, test. https://maven.apache.org/

Devon Burriss
  • 2,497
  • 1
  • 19
  • 21
  • I have come across maven but I didn't realize that it was also a build tool. I suppose my question would be that if it's the build tool and dependency manager then what are the overlaps with IDE .project files and the like. Do they play nice together without duplication? For the particular project I'm working on it appears that *Ivy* is the standard and that there are custom repositories stood up that are in use. I'm not sure whether Maven would be too drastic of a change from what is there already. – jpierson Oct 09 '15 at 20:07
2

At build time, there are tools like Maven and Gradle. These allow your dependencies, and the tool builds the dependency graph to determine the required transitive dependencies. Both Maven and Gradle represent the dependencies in directed acyclic-graph, but Maven's DAG is far more constrained than Gradle's. Maven is very declarative, specified in XML, and is very much our way or the highway. Gradle is very flexible, with build scripts specified as Groovy programs. Here's a feature-by-feature comparison (biased towards Gradle).

As far as Maven is concerned, all you have to do is:

mvn clean install

If you want to visualize the dependency graph:

mvn dependency:tree

At run time, it's a different story.

Typically, Java applications are bundled into WAR or EAR files. These are glorified ZIP files which contain the application and all of its dependencies. A WAR file looks like this, unpacked:

+-+ WEB-INF
| |
| +-- classes
| |    \_ application specific classes
| +-- lib
| |    \_ bundled JAR files for required dependencies
| +-- web.xml
|      \_ main web application configuration
+-- ... web assets

WAR and EAR files are deployed onto an application server (Tomcat, JBoss, etc.), which manages shared dependencies between applications.

Outside of application servers, it's a bit tricky. The simplest approach is to install the application as an executable JAR file with all of its dependencies installed along side it. JAR files can have a "MAINFEST.MF" file included with it that lists all of the dependent JARs. A build tool like Maven will automatically configure the JAR to reference its dependencies and package the application and its dependencies in a ZIP file (see the Maven assembly plugin).

Another approach is the so called "fat-JAR" or "uber-JAR" which is a JAR containing other JARs or the main JAR simply has the exploded contents of the dependency JARs (see the Maven shade plugin).

Finally, there is OSGi, which manages dependencies at runtime. OSGi is an open standard, implemented by containers such as Apache Felix or Eclipse Equinox. Here's an idea of how to set up an Eclipse Equinox application. You develop your application as a "plugin" into one of these frameworks. But, as a nice benefit, you can manage multiple versions of dependencies and even get auto-update.

sh0rug0ru
  • 1,596
  • 9
  • 9
  • Interesting, I've heard of Gradle before too but hadn't realized that it is a build tool. I'll look into it and see if it leads me to anything. At this point I'm trying to adapt this project to allow for build more maintainable build automation and a better developer experience but I don't want to change things too far from the root technologies that are being used. At the same time I still trying to grasp how many tools at play and what each tool does. – jpierson Oct 09 '15 at 20:16