为什么我的 Jnlp 程序不能与 log4j 一起使用?

发布于 2024-07-18 21:12:36 字数 5145 浏览 2 评论 0原文

我有以下问题: 我已经在 Tomcat 中部署了 JNLP 和可执行 JAR 文件。 JNLP 文件应自动下载 JAR 文件并执行它。 JAR 文件已签名并经过验证。 这样就完成了(下载部分)。 但是当执行JAR主类(JNLP文件中指定)时,出现问题: 执行部分主类代码。 之后,当它尝试加载声明了静态最终 org.apache.log4j.Logger 实例的类时,它会显示错误。

下面是JNLP文件的代表性部分、代码和错误。

JNLP

<?xml version='1.0' encoding='UTF-8'?>
<jnlp spec="1.5+" codebase="http://localhost:8080/examples" href="DemoInstaller.jnlp" download="eager" main="true">
    <information>
        <title>Demo Installer</title>
        <vendor>Codemart [www.codemart.ro]</vendor>
        <homepage>https://sourceforge.net/projects/cminstall/</homepage>
        <description>This is a demo installer built using Codemart Installer framework with JavaFX</description>
        <description kind="tooltip">Codemart Demo Installer</description>
        <offline-allowed />
        <shortcut online="true">
            <desktop />
        </shortcut>
    </information>

<security>
    <all-permissions />
</security>

<update check="background" />

<resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
            <jar href="DemoInstaller.jar" main="true" download="eager" />
</resources>

<application-desc main-class="ro.codemart.installer.packer.ant.impl.nestedjar.Main" />

主类:

public class Main {
 public static void main(String[] args) throws Exception {
     final Main main = new Main();
     //this is the problem class !
     Class clazz = Class.forName("WizardRunner");
     Method m = clazz.getMethod("main", new Class[]{args.getClass()});
     m.invoke(null, new Object[]{args});      
    ...
   }
}

问题类:

public class WizardRunner{

    private final static Logger log = Logger.getLogger(WizardRunner.class);
...
}

错误:

log4j:ERROR 找不到 [log4j.dtd]。 在搜索中使用了 [sun.misc.Launcher$AppClassLoader@d9f9c3] 类加载器。 log4j:错误无法解析 url [jar:http://localhost:8080/示例/DemoJar.jar!/log4j.xml]。 java.io.FileNotFoundException:在以下位置找不到 JAR 条目 log4j.dtd 在 com.sun.jnlp.JNLPCachedJarURLConnection.connect(来源未知) 在 com.sun.jnlp.JNLPCachedJarURLConnection.getInputStream(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(来源未知) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(来源未知) 在 com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(来源未知) 在 com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(来源未知) 在 com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(来源未知) 在 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(来源未知) 在 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(来源未知) 在 javax.xml.parsers.DocumentBuilder.parse(来源未知) 在 org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612) 在 org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711) 在 org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618) 在 org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470) 在 org.apache.log4j.LogManager.(LogManager.java:122) 在 org.apache.log4j.Logger.getLogger(Logger.java:117) 在 ro.codemart.installer.wizard.WizardRunner.(WizardRunner.java:38) 在 java.lang.Class.forName0(本机方法) 在 java.lang.Class.forName(来源未知) 在 ro.codemart.installer.packer.ant.impl.nestedjar.Main.executeApplicationMainClass(Main.java:216) 在 ro.codemart.installer.packer.ant.impl.nestedjar.Main.main(Main.java:290) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(来源未知) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(来源未知) 在 java.lang.reflect.Method.invoke(来源未知) 在 com.sun.javaws.Launcher.executeApplication(来源未知) 在 com.sun.javaws.Launcher.executeMainClass(来源未知) 在 com.sun.javaws.Launcher.doLaunchApp(来源未知) 在 com.sun.javaws.Launcher.run(来源未知) 在 java.lang.Thread.run(来源未知) log4j:WARN 找不到记录器 (WizardRunner) 的附加程序。 log4j:WARN 请正确初始化 log4j 系统。

谢谢你!

I have the following problem:
I've deployed in Tomcat a JNLP and an executable JAR files. JNLP file should automatically download the JAR file and execute it. The JAR file is signed and verified.
This is done (the downloading part).
But when to execute the JAR main class (specified in the JNLP file), a problem occurs:
A part of the main class code is executed. Afterwards, when it tries to load a class that has a static final org.apache.log4j.Logger instance declared, it says an error.

Below are the representative parts of the JNLP file, the code and the error.

JNLP

<?xml version='1.0' encoding='UTF-8'?>
<jnlp spec="1.5+" codebase="http://localhost:8080/examples" href="DemoInstaller.jnlp" download="eager" main="true">
    <information>
        <title>Demo Installer</title>
        <vendor>Codemart [www.codemart.ro]</vendor>
        <homepage>https://sourceforge.net/projects/cminstall/</homepage>
        <description>This is a demo installer built using Codemart Installer framework with JavaFX</description>
        <description kind="tooltip">Codemart Demo Installer</description>
        <offline-allowed />
        <shortcut online="true">
            <desktop />
        </shortcut>
    </information>

<security>
    <all-permissions />
</security>

<update check="background" />

<resources>
    <j2se href="http://java.sun.com/products/autodl/j2se" version="1.6+" />
            <jar href="DemoInstaller.jar" main="true" download="eager" />
</resources>

<application-desc main-class="ro.codemart.installer.packer.ant.impl.nestedjar.Main" />

The main class:

public class Main {
 public static void main(String[] args) throws Exception {
     final Main main = new Main();
     //this is the problem class !
     Class clazz = Class.forName("WizardRunner");
     Method m = clazz.getMethod("main", new Class[]{args.getClass()});
     m.invoke(null, new Object[]{args});      
    ...
   }
}

And the problem class:

public class WizardRunner{

    private final static Logger log = Logger.getLogger(WizardRunner.class);
...
}

And the error:

log4j:ERROR Could not find [log4j.dtd]. Used [sun.misc.Launcher$AppClassLoader@d9f9c3] class loader in the search.
log4j:ERROR Could not parse url [jar:http://localhost:8080/examples/DemoJar.jar!/log4j.xml].
java.io.FileNotFoundException: JAR entry log4j.dtd not found in
at com.sun.jnlp.JNLPCachedJarURLConnection.connect(Unknown Source)
at com.sun.jnlp.JNLPCachedJarURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator$2.parse(DOMConfigurator.java:612)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:711)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
at org.apache.log4j.LogManager.(LogManager.java:122)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at ro.codemart.installer.wizard.WizardRunner.(WizardRunner.java:38)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ro.codemart.installer.packer.ant.impl.nestedjar.Main.executeApplicationMainClass(Main.java:216)
at ro.codemart.installer.packer.ant.impl.nestedjar.Main.main(Main.java:290)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
log4j:WARN No appenders could be found for logger (WizardRunner).
log4j:WARN Please initialize the log4j system properly.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

慢慢从新开始 2024-07-25 21:12:36

我认为问题在于缺少 log4j.jar - 它不是由 .jnlp 文件指定或加载的。 您在前面的答案中提到它位于您的类路径中,但是如果您通过 WebStart 运行怎么办? 我相信您的类路径仅限于 .jnlp 文件中定义的内容。

尝试添加

<jar href="log4j.jar" main="true" download="eager" />

<resources>

I think the problem is missing log4j.jar - it's not specified or loaded by the .jnlp file. You mentioned in the previous answer that it's in your classpath, but how if you're running via WebStart? I believe your classpath is limited to what's defined in the .jnlp file.

Try adding

<jar href="log4j.jar" main="true" download="eager" />

to

<resources>
喵星人汪星人 2024-07-25 21:12:36

如果查看堆栈跟踪,错误的原因是 log4j.dtd 的 FileNotFoundException。 查看如何从 log4j.xml 引用 DTD。 DTD 是否包含在您的 jar 文件中? 它需要位于 JVM 可以加载它的位置。

If you look in your stack trace the cause of the error is a FileNotFoundException for log4j.dtd. Look at how the DTD is referenced from your log4j.xml. Is the DTD included in your jar file? It needs to be in a place where the JVM can load it.

没有心的人 2024-07-25 21:12:36

是的,log4j.dtd 文件嵌入了 log4j-1.2.12.jar。 此 log4j jar 也位于类路径中。

Yes, the log4j.dtd file comes embedded with log4j-1.2.12.jar. Also this log4j jar is in the classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文