私は、Javaクラスファイルからいくつかの定数を取得し、ファイル名のバージョン番号として使用する単純なビルドスクリプトに取り組んでいます。私はEclipseとそれ自身のAntを使用しますが、bcel-5.2.jarをlibsフォルダに、Ant呼び出しのクラスパスに入れてください。Ant loadpropertiesが失敗しました(bcel error?)
<target name="generate_version" depends="compile">
<loadproperties srcfile="${dir.dest}/MyVersion.class">
<classpath>
<fileset dir="${dir.libs}">
<include name="**/bcel*.jar"/>
</fileset>
</classpath>
<filterchain>
<classconstants/>
</filterchain>
</loadproperties>
</target>
しかし、残念ながら、Antタスクが失敗したloadproperties:結果は
set ANT_HOME=C:\Program Files\Java\ant\apache-ant-1.7.1
"%ANT_HOME%\bin\ant.bat"
:その後
build.xml:46: expected a java resource as source
私は、このコマンドラインを使用して、Eclipseの外部からのAntを実行しようとしました
Buildfile: build.xml
init:
[echo] Building project.
[echo] ant.home: C:\Program Files\Java\ant\apache-ant-1.7.1
[echo] ant.java.version: 1.6
[echo] ant.version: Apache Ant version 1.7.1 compiled on June 27 2008
compile:
[javac] Compiling 262 source files to **********\build
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
generate_version:
BUILD FAILED
********************\ant\build.xml:46: expected a java resource as source
私は本当に失われました。それはbcelエラーですか?それは私自身のbcelとAntの非互換性ですか?
つ最後ヒント:このにおけるAntターゲット結果からBCELクラスパスエントリを削除:
Buildfile: build.xml
init:
[echo] Building project.
[echo] ant.home: C:\Program Files\Java\ant\apache-ant-1.7.1
[echo] ant.java.version: 1.6
[echo] ant.version: Apache Ant version 1.7.1 compiled on June 27 2008
compile:
[javac] Compiling 262 source files to ********************\build
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
generate_version:
BUILD FAILED
java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassParser
at org.apache.tools.ant.filters.util.JavaClassHelper.getConstants(JavaClassHelper.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
UPDATE EclipseでAntのプリファレンスを設定した後、エラーメッセージが変更された:
BUILD FAILED
*********************\build.xml:46: org.apache.bcel.classfile.ClassFormatException: is not a Java .class file
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
をこれはおそらく、AntとBCELの間のバージョンの競合だと思います。またはBCELとJDK1.6。あるいはEclipseとBCEL、AntやJDK ...私は迷っています。
ANSWER:
これは
下回ったコメントです私はこれを言及している必要があります - あなたは何を変換する必要はありません。 Doc: "Ant 1.7以降、ISO-8859-1の文字エンコーディングは、文字を バイトに変換するために使用されるため、このエンコーディングを使用してJavaクラスファイルを読み込む必要があります。これは、生のバイトで文字フィルタが使用されているという事実を知るための慣習に過ぎません。 ant.apache.org/manual/CoreTypes/... UTF-8を使用すると問題になります! - McDowell
これは、BCELとJDKの互換性の問題が発生すると思います。 「Java .classファイルではありません」は、BCELで認識されない不一致クラス・バージョン(.classの最初の4バイト)を指します。 JDK1.4でもう一度コンパイルしようとしています。 – cringe