- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一个简单的构建脚本,它应该从 java 类文件中获取一些常量并将它们用作我的文件名中的版本号。我使用 Eclipse 和它自己的 Ant,但将 bcel-5.2.jar 放在我的 libs 文件夹中并放入 Ant 调用的类路径中。
<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 失败了:
build.xml:46: expected a java resource as source
之后,我尝试使用以下命令行从 Eclipse 外部运行 Ant:
set ANT_HOME=C:\Program Files\Java\ant\apache-ant-1.7.1
"%ANT_HOME%\bin\ant.bat"
结果是
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 错误吗?是不是 Ant 和我自己的 bcel 不兼容?
最后一个提示:从 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)
更新 在 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……我迷路了。
回答:
这是下面的评论
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
最佳答案
废话,我就知道!它归结为文件编码问题。这些文件仍在 ISO-8819-1 中,但我使用的是 UTF-8。该项目相当陈旧,并且是使用错误的编码创建的。在 javac 和 loadproperties 任务中设置参数 encoding 修复它。
<target name="generate_version" depends="compile">
<loadproperties encoding="iso-8859-1" srcfile="${dir.dest}/MyVersion.class">
<filterchain>
<classconstants/>
</filterchain>
</loadproperties>
</target>
我认为它已被我们的 Subversion 服务器更改,但我认为我现在必须自己将每个文件转换为 UTF-8...认为这是 SO 的另一个问题。
关于java - Ant loadproperties 失败(bcel 错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/876840/
使用 Entity Framework ,您可以执行类似这样的操作,通过查询为多个引用加载对象。 var Customer = context.Customers.Include(x=>x.Order
在 POCO 中,我通过 LoadProperty 使用显式加载来加载数据。我需要从加载的属性中过滤和排序数据并返回主对象。 比如说,有一个相册类,其中的照片是一个集合。我需要从 DAL 返回“专辑”
我正在编写一个简单的构建脚本,它应该从 java 类文件中获取一些常量并将它们用作我的文件名中的版本号。我使用 Eclipse 和它自己的 Ant,但将 bcel-5.2.jar 放在我的 libs
我将我的 Entity Framework 4.3 数据库第一个项目升级到新的 Entity Framework 5。显然我现在使用的是 DbContext 而不是 ObjectContext。 我用
本文整理了Java中com.ibm.wala.properties.WalaProperties.loadProperties()方法的一些代码示例,展示了WalaProperties.loadPro
我有一个服务消耗许多外部服务。我正在为每个文件创建属性文件,这些是相当多的预定义属性,例如 twl.props、tweet.props、hubpot.props 等 为了在运行时获取这些属性,我使用
我的属性文件中有以 base64 编码的内容(其中有密码,我只想不是纯文本)。当我在 Ant 中创建一个 loadproperties 任务时,如下所示: 然后尝试运行 build.xml 中的任何
我是一名优秀的程序员,十分优秀!