views:

161

answers:

4

We have a Java codebase that is currently one Web-based Netbeans project. As our organization and codebase grows it seems obvious that we should partition the various independent pieces of our system into individual jars. So one Jar library for the data access layer, one for a general lib, one for a specialized knowledge access, etc. Then we'd have a separate project for the web application, and could have one for a command line tools app, another web app eventually, etc.

What is the recommended practice for doing and managing this? Is it Maven? Can it all be effectively done with just Netbeans alone by simply creating individual projects and setting the dependecies of one project on the jar files of the others?

A: 

I would create ant scripts to build the pieces and for deployment. Then you are not depending on your IDE for build/deployment.

sepang
A: 

I would definitely say check Maven(2) out. It is very good for doing this sort of thing. You can define individual models and version then very easily. Netbeans also does a decent job of integrating with.

Also I suggest you set up Archiva which will let you be dependent upon binaries of other artifacts that your company generates internally. This also acts as a proxy and will keep a local copy of any external dependencies your projects might have so its very quick to get the new versions internally.

Steve g
A: 

It sounds like your code is getting to the point where you're graduating from the WAR approach and have entered into the EAR level.

An EAR is just another archive that contains all the other JARs and WARs that get combined to create an application. There are four types of modules that can reside inside it, Web, EJB, Connectors and Utilities. Most people only use Web and Utilities so they go with using the WEB-INF/lib approach.

But if you're starting to get a lot of interdependencies what you do create an EAR project and make your web project a child of it. Each Utility JAR which is just straight Java code used by other modules also becomes a child of the EAR. Finally in each of your projects there should be a META-INF/manifest.mf file that just has the name of the JARs that JAR/WAR depends on.

I'm an eclipse guy and most of this gets taken care of for you in eclipse, but I'm sure netbeans has very similar functionality.

Now the only problem is that you have to use a full JEE server to deploy an EAR so I don't think you can use Tomcat if that's what you're currently using.

William
There is no need to do this if it is a Web project only without any other JEE component. Simply dropping your jars in the web apps lib directory is simpler as no manifest update is needed. Even if the war is deployed in an EAR.
Robin
+2  A: 

I'd agree with SteveG above on using Maven2 to help you modularise your code base, but I'd use Nexus as the local repository for Maven instead of Archiva. The guys at Sonatype also have an excellent (free html/pdf) book on how to use Maven, Nexus, and integrate it into IDEs.

Be careful on how you decide to partition up your projects, though. There's no sense in over-complicating your dependencies just for the sake of it.

lawsonj2019