私が取り組んでいるオープンソースのJavaプロジェクトがあります。ソースコードを直接操作すると、すべてが適切に機能しますが、コードから jar を作成し、jar を介して同じクラスを参照しようとするとExceptionInInitlaizerError
、Unknown Source
. 後で、それは示しますNoClassDefFoundError
。以下は、4 回のテスト実行のスタック トレースです。
jar での出力:
java.lang.ExceptionInInitializerError
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:8)
Caused by: java.lang.RuntimeException: internal error
at mf.org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl.applyFacets1(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.BaseSchemaDVFactory.createBuiltInTypes(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl.createBuiltInTypes(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl.<clinit>(Unknown Source)
... 9 more
Test 1: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:11)
Test 2: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:14)
Test 3: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:17)
Test 4: false
すべてのソース パッケージをプロジェクトに直接コピーし、同じコードを実行すると、適切な出力が得られます。
Test 1: true
Test 2: true
Test 3: true
Test 4: true
別のテスト jar を作成して、jar プロセスが正しく、適切に使用できることを確認しました。
コードがソースでは機能するが、jar では機能しない理由はありますか?
EDT: 要求に応じて、jar を作成するための ant コード
jar ファイルの作成方法に関するコードを要求しました。jar を作成するために jar のサンプル ant コードを使用しました。以下は私の ant ファイルです。
<project name="Xerces-For-Android" default="dist" basedir=".">
<description>
Builds jar for Xerces-For-Android
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="clean, init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac verbose="true" target="1.6" srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the .jar file -->
<jar jarfile="${dist}/lib/Xerces-For-Android.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
EDT: jar ファイルを使用したプログラムの実行に詳細を追加しました。以下は出力の一部です。
[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
...
[Loaded java.lang.Enum from shared objects file]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$UnionToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$ParenToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$ClosureToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$ConcatToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$ConditionToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$ModifierToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$CharToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.Token$StringToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded mf.org.apache.xerces.impl.xpath.regex.RangeToken from file:/C:/path/to/workspace/Sandbox/libs/Xerces-For-Android.jar]
[Loaded java.util.ResourceBundle from shared objects file]
[Loaded java.util.ResourceBundle$1 from shared objects file]
[Loaded java.util.ResourceBundle$Control from shared objects file]
[Loaded java.util.Arrays$ArrayList from shared objects file]
[Loaded java.util.Collections$UnmodifiableCollection from shared objects file]
[Loaded java.util.Collections$UnmodifiableList from shared objects file]
[Loaded java.util.Collections$UnmodifiableRandomAccessList from shared objects file]
[Loaded java.util.ResourceBundle$CacheKey from shared objects file]
[Loaded java.util.ResourceBundle$CacheKeyReference from shared objects file]
[Loaded java.util.ResourceBundle$LoaderReference from shared objects file]
[Loaded java.util.ResourceBundle$Control$1 from shared objects file]
[Loaded sun.misc.Launcher$1 from shared objects file]
[Loaded sun.misc.Launcher$2 from shared objects file]
[Loaded java.net.URLClassLoader$2 from shared objects file]
[Loaded java.util.ResourceBundle$BundleReference from shared objects file]
[Loaded java.lang.ExceptionInInitializerError from shared objects file]
java.lang.ExceptionInInitializerError
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:8)
Caused by: java.lang.RuntimeException: internal error
at mf.org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl.applyFacets1(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.BaseSchemaDVFactory.createBuiltInTypes(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl.createBuiltInTypes(Unknown Source)
at mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl.<clinit>(Unknown Source)
... 9 more
Test 1: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:11)
Test 2: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:14)
Test 3: false
java.lang.NoClassDefFoundError: Could not initialize class mf.org.apache.xerces.impl.dv.xs.SchemaDVFactoryImpl
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.dv.SchemaDVFactory.getInstance(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.reset(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at mf.javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at xml.MFXMLUtil.validate(MFXMLUtil.java:33)
at xml.MFXMLTester.main(MFXMLTester.java:17)
Test 4: false
[Loaded java.lang.Shutdown from shared objects file]
[Loaded java.lang.Shutdown$Lock from shared objects file]