Java/Eclipse equivalent of Visual Studio Console app + Class Library solution
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开发者_JS百科 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?
In eclipse you can proceed the same way you do in VS:
- Create an independent project for each class library (JAR) you want to share functionality with
- 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.
Well, i don't know if there is an "automatic" function which can creates the JAR file from your project. Today I'm using Rational Application Developer (very similar to eclipse), but I've used Eclipse and Netbeans too, and i can't remember that feature.
Maybe you can create a keyboard shorcut (read manual..) ;)
By the way, you can't "add a project" to a library. I think it's the other way round. I mean, you reference library from projects, not projects from libraries. What you have to do is:
- Create your library and export it to a jar.
- Then create a second project an add that jar to this project.
- Create more projects and do the same..
- If you change your library, you just have to replace the jar.
Hope this helps
PD: Seems that Pablo knows what he talks about. I'm just a noob programmer. Read his solution..
精彩评论