简体   繁体   English

我需要log4j 1.2和2.5共存于同一webapp中

[英]I need log4j 1.2 and 2.5 to coexist in the same webapp

I have a java webapp that uses Crystal's Business Objects runtime to run a report coded in that technology. 我有一个Java Webapp,它使用Crystal的Business Objects运行时来运行以该技术编码的报表。 The problem is that the monkeys at Crystal directly referenced a method in a log4j 1.2 class. 问题在于Crystal的猴子直接引用了log4j 1.2类中的方法。 This method isn't part of the log4j 1.2 to 2.5 bridge api. 此方法不是log4j 1.2至2.5桥api的一部分。 Nor should it be because Crystal shouldn't be calling it directly. 也不应该是因为Crystal不应该直接调用它。

I have no choice but to use Crystal, our organization is locked in on it. 除了使用Crystal之外,我别无选择,我们的组织已陷入困境。 I can only choose to either roll back the entire app to NOT use log4j2.5 like all of our other apps, OR I need to find a way they can coexist. 我只能选择回滚整个应用程序而不像其他所有应用程序那样使用log4j2.5,或者我需要找到一种它们可以共存的方式。 When i put both jars in the classpath, the app tends to get confused as to what to load and we get no logging out. 当我将两个罐子都放在类路径中时,该应用程序往往对要加载的内容感到困惑,并且没有注销。 Remove that jar, and logging works great...but Crystal bombs. 删除那个罐子,伐木效果很好...但是水晶炸弹。

I really don't want to roll everything back to 1.2. 我真的不想将所有内容回滚到1.2。 Is there a way to make them coexist nicely? 有没有办法使它们很好地共存? Like make 1.2 higher on the classloader only when calling Crystal or something? 像仅在调用Crystal或其他方法时使classloader上的1.2更高? Anyone know some trick that can help me here? 有人知道一些可以帮助我的窍门吗?

proxy-object proxy-object library 代理对象 代理对象库

Put Crystal jar and all its dependencies in a folder (/path/to/crystalLib/) 将Crystal jar及其所有依赖项放在文件夹(/ path / to / crystalLib /)中

Code Examples 程式码范例

Create any class from the Crystal library: 从Crystal库中创建任何类:

    File libDir = new File("/path/to/crystalLib/");

    ProxyCallerInterface caller = ObjectBuilder.builder()
            .setClassName("org.crystal.report")
            .setArtifact(DirArtifact.builder()
                    .withClazz(this.getClass())
                    .withVersionInfo(newVersionInfo(libDir))
                    .build())
            .build();
    String version = caller.call("crystalMethod").asString();

proxy-object library will handle separate class loader mess and you should be able to load any conflicting dependancies this way. 代理对象库将处理单独的类加载器混乱,您应该能够以这种方式加载任何冲突的依赖关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM