蚂蚁loadproperties失败(BCEL错误?) [英] Ant loadproperties failed (bcel error?)

查看:229
本文介绍了蚂蚁loadproperties失败(BCEL错误?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个简单的构建脚本应该从一个Java类文件获取一些常量,并将它们作为我的文件名中的版本号。我使用Eclipse和自己的蚂蚁,但放的 BCEL-5.2.jar 的在我的libs文件夹和到类路径的蚂蚁电话。

 <目标名称=generate_version依赖=编译>
&所述; loadproperties SRCFILE =$ {dir.dest} /MyVersion.class>
<&类路径GT;
<文件集DIR =$ {} dir.libs>
<包括姓名=** / BCEL的* .jar/>
< /文件集>
< /类路径>< filterchain>
< classconstants />
< / filterchain>
< / loadproperties>
< /目标与GT;

但不幸的是Ant任务的 loadproperties 的失败:

 的build.xml:46:预期Java资源源

之后,我试图从外面的Eclipse运行Ant,使用此命令行:

 设置ANT_HOME = C:\\ Program Files文件\\的Java \\蚂蚁\\ Apache的ANT-1.7.1
%ANT_HOME%\\ BIN \\ ant.bat

的结果是

 构建文件:build.xml文件在里面:
     [回应]大厦项目。
     [回应] ant.home:C:\\ Program Files文件\\的Java \\蚂蚁\\ Apache的ANT-1.7.1
     [回应] ant.java.version:1.6
     [回应] ant.version:Apache Ant的1.7.1版本于2008年6月27日编译编译:
    [javac的] 262编译源文件********** \\构建
    [javac的]注:某些输入文件使用或覆盖脱precated API。
    [javac的]注:重新编译-Xlint:详情德precation。
    [javac的]注:某些输入文件使用未经检查或不安全的操作。
    [javac的]注:重新编译-Xlint:未选中的详细信息。generate_version:构建失败
******************** \\蚂蚁\\的build.xml:46:预期Java资源源

我真的现在丢失。它是一个BCEL错误?它是一个Ant不兼容性我自己BCEL?

最后一个提示:删除从Ant目标结果BCEL类路径条目在此:

 构建文件:build.xml文件在里面:
     [回应]大厦项目。
     [回应] ant.home:C:\\ Program Files文件\\的Java \\蚂蚁\\ Apache的ANT-1.7.1
     [回应] ant.java.version:1.6
     [回应] ant.version:Apache Ant的1.7.1版本于2008年6月27日编译编译:
    [javac的] 262编译源文件******************** \\构建
    [javac的]注:某些输入文件使用或覆盖脱precated API。
    [javac的]注:重新编译-Xlint:详情德precation。
    [javac的]注:某些输入文件使用未经检查或不安全的操作。
    [javac的]注:重新编译-Xlint:未选中的详细信息。generate_version:构建失败
java.lang.NoClassDefFoundError的:组织/阿帕奇/ BCEL /类文件/ ClassParser
        在org.apache.tools.ant.filters.util.JavaClassHelper.getConstants(JavaClassHelper.java:47)
        在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
        在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

更新在Eclipse中设置的Ant preferences后,错误信息更改:

 构建失败
********************* \\的build.xml:46:org.apache.bcel.classfile.ClassFormatException:不是Java的.class文件
    在org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
    在org.apache.tools.ant.Task.perform(Task.java:348)
    在org.apache.tools.ant.Target.execute(Target.java:357)
    在org.apache.tools.ant.Target.performTasks(Target.java:385)
    在org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    在org.apache.tools.ant.Project.executeTarget(Project.java:1298)
    在org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    在org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    在org.apache.tools.ant.Project.executeTargets(Project.java:1181)
    在org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
    在org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

现在我认为这是可能的Ant和BCEL的版本冲突。或BCEL和JDK1.6。或者Eclipse和BCEL和蚂蚁或JDK ...我迷路了。


答:

这是发现低于

评论

  

我应该提到这一点 - 你不需要任何东西转换。文档:因为蚂蚁
  1.7编码ISO 8859-1的字符被用来从字符转换回
  字节,因此,人们必须使用此编码读取Java类文件。这仅仅是一个
  公约避开一个字符过滤器正在对原始字节使用的事实。
  ant.apache.org/manual/CoreTypes/...使用UTF-8将是坏! - 麦克道尔



解决方案

废话,我就知道!归结到一点,文件编码的问题。这些文件仍处于ISO-8819-1,但我使用UTF-8。该项目是老年pretty,并与到位错误编码创建。设置参数的编码的在的javac 的和的 loadproperties 的任务修复它。

 <目标名称=generate_version依赖=编译>
< loadproperties编码=ISO-8859-1SRCFILE =$ {} dir.dest /My​​Version.class>
< filterchain>
< classconstants />
< / filterchain>
< / loadproperties>
< /目标与GT;

我以为它得到了我们的Subversion服务器变了,但我想我必须每一个文件转换为UTF-8现在我...以为是这么一个问题。

I'm working on a simple build script that should get some constants from a java class file and use them as the version numbers in my file names. I use Eclipse and its own Ant, but put bcel-5.2.jar in my libs folder and into the classpath for the Ant call.

<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>

But unfortunatly the ant task loadproperties fails:

build.xml:46: expected a java resource as source

After that I tried to run Ant from outside Eclipse, using this command line:

set ANT_HOME=C:\Program Files\Java\ant\apache-ant-1.7.1
"%ANT_HOME%\bin\ant.bat"

The result is

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

I'm really lost now. Is it a bcel error? Is it an Ant incompatibility with my own bcel?

One last hint: Removing the bcel classpath entry from the Ant target results in this:

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 After setting the Ant preferences in Eclipse, the error message changed:

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)

Now I think it's maybe a version conflict between Ant and BCEL. Or BCEL and JDK1.6. Or Eclipse and BCEL and Ant or JDK... I'm lost.


ANSWER:

This is the comment found below

I should have mentioned this - you do not need to convert anything. Doc: "since Ant 1.7, the character encoding ISO-8859-1 is used to convert from characters back to bytes, so ONE HAS TO USE THIS ENCODING for reading the java class file." This is just a convention to get round the fact that a character filter is being used on raw bytes. ant.apache.org/manual/CoreTypes/… Using UTF-8 would be bad! – McDowell

解决方案

Crap, I knew it! It comes down to file encoding issues. The files are still in ISO-8819-1, but I'm using UTF-8. The project is pretty aged and was created with the wrong encoding in place. Setting the parameter encoding in the javac and loadproperties Task fixes it.

<target name="generate_version" depends="compile">
	<loadproperties encoding="iso-8859-1" srcfile="${dir.dest}/MyVersion.class">
		<filterchain>
			<classconstants/>
		</filterchain>
	</loadproperties>
</target>

I thought it got changed by our Subversion server, but I think I have to convert every single file to UTF-8 myself now... think that is another question for SO.

这篇关于蚂蚁loadproperties失败(BCEL错误?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆