开发者

Java best practices of placing and linking external JARs in a Eclipse project?

I'm just getting back into Java and I've been trying to figure out how exactly I should be organizing my project. I come from a C# background where you just have to make sure that the libraries you compile are retrievable by the executable (or other libraries) by keeping them in the same folders or subfolders, but java seems to do things differently.

In my Eclipse workspace I have my main project I'm working on (just one for now, more later) and it references external JARs (in my case, the gazillion of files of Apache Axis2).

Where should I be storing these libraries that my projects dep开发者_如何学Goends on when building? I will need to add everything to source control really soon, and so I can't keep referencing these JARs by absolute path on my machine. I read suggestions for putting this IN a subfolder of my main project, but I feel that's not ideal. I think I should be keeping them in the same source-controlled parent folder as the project, and somehow reference them through relative path (eclipse one does absolute path through the UI, really?), so something like:

c:\JavaProjects\MyProject c:\JavaProjects\axis2-1.5.4 c:\JavaProjects\%whatever other library%

Is there an even better way?


Ideally, you shouldn't be storing the libraries in your project. They can be retrieved by public (or private) repositories via so called dependency-management tools. The two most prominent ones are Maven and Ivy.

Eclipse (and any other IDE) has integration with these tools (via plugins) and adds the desired libraries to the classpath automatically. You only have to define them (together with their version) in a configuration file.


The learning curve is a bit steap, but I would really consider using Maven.

The M2Eclipse will be needed for full integration though.


Take the time to learn and use Maven 3.

Set up a private repository manager, I use Archiva.

Use Jenkins for continuious integration, it works with Maven seamlessly.

This does take some time and effort, but when it is configured, it doesn't really need to be touched again and makes one step build and deployment a snap!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜