R – Java/Eclipse equivalent of Visual Studio Console app + Class Library solution

class-libraryeclipsejar

I'm a .Net developer, but for my current project I have to create some Java code. I did some Java coding in the past (I even learned OOP using Java), but am new to Eclipse, which I have to use.

I have to create a few Java console applications that share common functionality. I want to bundle that common functionality into one library (JAR file) and use that file from the command line programs. When I change the library, all dependent console applications also have to be rebuilt.

In Visual Studio (.Net) I would create a new solution and add one "Class Library" project and multiple "Console Application" projects and make them dependent on the Class Library. I'm having trouble recreating the same setup using Eclipse/Java. I guess the Java equivalent of a .Net Class Library is a JAR file. However, I haven't yet found out how to create a JAR file project in Eclipse (I can export a project to a JAR, but that's a manual step; I like this to go automatically) and reference this JAR project from multiple "normal" Java projects.

I hope I've explained myself clearly. Can anybody shed some light?

Best Answer

In eclipse you can proceed the same way you do in VS:

  1. Create an independent project for each class library (JAR) you want to share functionality with
  2. Create a project for each console application. On this project properties window, make it dependent on the other class library projects by selecting the projects you need

For automatic deployment, you can have an ANT task to make all the automated processing you need to generate all the files.