日期:2014-05-18  浏览次数:20660 次

如何解决包的版本不兼容问题?
情况是这样的:
struts2最新版使用了apache lang组件包,commons-lang3x.jar
我需要使用commons-configura来读取properites文件。但commons-configura依赖的却是:
commons-lang2x.jar

两个版本的commons-lang.jar放入classpath 出错。
使用commons-lang2x.jar struts2会出错
使用commons-lang3x.jar commons-congigure就会出错。

该怎么弄啊,我不是第一次遇到这个问题了,json-lib与最新版本的struts2也存在同样的问题。当时我直接放弃了json-lib。


有没有办法在一个project中做多个classpath,指定某一个类或几个类使用 特定的classpath?
或是其他的解决办法啊?
commons-lang3 json-lib struts2

------解决方案--------------------
我觉得按照你的情况,删除低版本比较好,至于需要使用commons-configura来读取properites文件,你可以通过其他方式解决。
读取properites的方式应该很多。
ava读取Properties文件的六种方法
Java读取properties文件 【转】

使用J2SE API读取Properties文件的六种方法

1。使用java.util.Properties类的load()方法
示例: InputStream in = lnew BufferedInputStream(new FileInputStream(name));
Properties p = new Properties();
p.load(in);

2。使用java.util.ResourceBundle类的getBundle()方法
示例: ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault());

3。使用java.util.PropertyResourceBundle类的构造函数
示例: InputStream in = new BufferedInputStream(new FileInputStream(name));
ResourceBundle rb = new PropertyResourceBundle(in);

4。使用class变量的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getResourceAsStream(name);
Properties p = new Properties();
p.load(in);

5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法
示例: InputStream in = JProperties.class.getClassLoader().getResourceAsStream(name);
Properties p = new Properties();
p.load(in);

6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法
示例: InputStream in = ClassLoader.getSystemResourceAsStream(name);
Properties p = new Properties();
p.load(in);