开发者

Java: Use jar library's from package manager in Linux

I'm trying to find the best way to use Java libraries that were installed by the package manager instead of just putting a copy into ${project.root}/lib

My distro, Gentoo, has a package for Java libraries like jdbc-postgresql.

It's installed to /usr/share/jdbc-postgresql/lib/jdbc-post开发者_StackOverflow社区gresql.jar

I assume that this path may be different in Ubuntu, Fedora, or Arch.

Is there any way to do like what C does? Where you just add a -lfoo, and the linker would find libfoo.so.

I'm using Ant 1.8.0 and Java 1.6.0_19.


Maven and Ivy both do something similar but in the end you still end up with jars added to the lib folder of your application.

Also you would loose control over the versions of your jars your application will use runtime. If an update to your distribution changes these jars your application could fail from changing API signature. Deploying on computers other than your own could also pose problems to locate these jars. Lastly if your application uses many jars you could have problem creating a classpath reaching the limits of what can be stored in an environment variable.

I do not know if there are such systems available for jars as building a lib folder is the approach most used, simple, safe with the light disadvantage to duplicate jars for each applications. This said disk space is cheap and jars rarely peak higher than 1 meg so it is minor.

This being said you could create an extention to Ivy for example that would make your system a repository, then the build process would copy the jars from the different locations in your system to the lib folder of your project thereby bypassing the classpath limits. The plugin could learn the location of the jars by using the package manager's database if available, you could discover versions as well fro the same source. This way you would support customized locations so long as the manager was used to install the jars.

That would be my first avenue of investigation to solve this if I had time and energy.

This being said I still wonder if the investment would yield sufficient return rather than just copy the jars. You are better judge than me to evaluate this for your own needs.


No, you should rely on $CLASSPATH variable, and system or shell script that run it should take care of properly setup $CLASSPATH path. Same will works in Windows, via %CLASSPATH%.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜