私の Jnlp プログラムが log4j で動作しないのはなぜですか?

StackOverflow https://stackoverflow.com/questions/852089

  •  21-08-2019
  •  | 
  •  

質問

次の問題があります。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:エラー [log4j.dtd] が見つかりませんでした。検索では [sun.misc.Launcher$AppClassLoader@d9f9c3] クラスローダーを使用しました。log4j:エラー URL を解析できませんでした [jar:http://localhost:8080/examples/DemoJar.jar!/log4j.xml]。java.io.FileNotFoundException:jar entry entry log4j.dtd com.sun.jnlp.jnlpcachedjarurlconnection.connect(不明なソース)com.sun.jnlp.jnlpcachedjarurlconnection.getinputStream(com.sun.org.xer.xerter.xerter.xerter.xerter.xerter.xerter.xerter.xerty.xerty.xerty.xerty.xerty.xerty.xer. .xmlentitymanager.setupCurrententity(不明なソース)com.sun.org.apache.xerces.internal.impl.xmlentitymanager.startentity(未知のソース)com.sun.org.apache.xerces.internal.impl.xmlentitymanager.startdttntity(不明)ソース)com.sun.org.apache.xerces.internal.impl.xmldtdscannerimpl.setinputsource(unknown source)at com.sun.org.org.apache.xerces.internal.impl.xmldocumentscannerimpl $ dtddriver.dispatch(未知のソース) .sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl $ dtddriver.next(unknown source)at com.sun.org.apache.cherces.internal.impl.xmldocumentscannerimpl com.sunsunsunsunnext(未知のソース) .org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(不明なソース)com.sun.org.org.apache.xerces.internal.impl.xmldocumentfragmentsnerimpl.scandocument(com.sun.org.apache.xer .internal.parsers.xml11Configuration.parse(不明な情報源)com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(不明なソース)com.sun.org.apache.xerces.internal.parsers.xmlparsererererererer .sun.org.org.apache.xerces.internal.parsers.domparser.parse(不明な情報源)com.sun.org.apache.xerces.internal.jaxp.documentbuilderimpl.parse(不明な情報源)のparse(不明なソース) javax.xml.parsers.documentbuilder.parse(不明な情報源)org.apache.log4j.xml.domconfigurator $ 2.parse(domconfigurator.java:612)at org.apache.log4j.xml.domconfiguretor.doconfigure(doconfigureator) :711)atorg.apache.log4j.xml.domconfigurator.doconfigure(domconfigurator.java:618)at org.apache.log4j.helpers.optionconverter.selectandConfigure(optionConverter.java:470) (logmanager.java:122)at org.apache.log4j.logger.getlogger(logger.java:117)at ro.codemart.installer.wizard.wizardrunner(wizardrunner.java:38) (ネイティブメソッド)java.lang.class.forrase(不明なソース)ro.codemart.installer.packer.ant.ant.nestedjar.main.executeapplicationmainclass(main.java:216)のro.codemart.installer.packer。 ant.impl.nestedjar.main.main.main(main.java:290)at sun.reflect.nativemethodaccessorimpl.invoke0(native method)at sun.refllect.nativemethodaccessorimpl.invoke(不明な情報源)ソース)Java.lang.Reflect.Method.Invoke(不明な情報源)com.sun.javaws.launcher.executeapplication(com.sun.javaws.launcher.executemainclassのcom.sun.javawsのcom.sun.javaws.launcher.executemainclass .launcher.dolaunchApp(不明なソース)com.sun.javaws.launcher.run(不明なソース)java.lang.thread.run(不明なソース)log4j:warn warn logger(wizardrunner)の付録は見つかりませんでした。log4j:WARN log4j システムを適切に初期化してください。

ありがとう!

役に立ちましたか?

解決

問題は log4j.jar が欠落していることだと思います。これは .jnlp ファイルによって指定されていないか、ロードされていません。前の回答では、それがクラスパス内にあると述べましたが、WebStart 経由で実行している場合はどうすればよいでしょうか?クラスパスは .jnlp ファイルで定義されているものに限定されていると思います。

追加してみてください

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

<resources>

他のヒント

スタック トレースを確認すると、エラーの原因は log4j.dtd の FileNotFoundException です。DTD が log4j.xml からどのように参照されているかを確認してください。DTD は jar ファイルに含まれていますか?JVM がロードできる場所に存在する必要があります。

はい ログ4j.dtd ファイルには埋め込まれています log4j-1.2.12.jar. 。また、この log4j jar はクラスパス内にあります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top