简体   繁体   English

如何使用ANT构建具有不同Java版本的jar

[英]How to build a jar with different java version with ANT

I tried to build a jar file using java 1.5. 我尝试使用Java 1.5构建jar文件。 I use eclise and I specified the java version as 1.5 in below areas. 我使用eclise,并在以下区域中将Java版本指定为1.5。

  • Project -> Properties -> Java Compiler 项目->属性-> Java编译器
  • Project -> Java Build Path -> JRE System Library 项目-> Java构建路径-> JRE系统库
  • Ant Build File -> Run As -> ExternalToolConfiguration -> JRE 蚂蚁构建文件->运行方式-> ExternalToolConfiguration-> JRE

But after the jar is built all the classes were built in 1.7 (major version 51) I want them in 1.5.(49) This is the result for javap -verbose MyClassInBuiltJar 但是在构建jar之后,所有类都在1.7(主要版本51)中构建,我希望在1.5中构建它们。(49)这是javap -verbose MyClassInBuiltJar的结果

SourceFile: "Program.java"
minor version: 0
major version: 51
Constant pool:

It's probably not ANT that cause the issue, you may need to change the project's JRE and recompile the project with the 1.5 JRE . 引起问题的可能不是ANT,您可能需要更改项目的JRE并使用1.5 JRE重新编译项目。

You can also try to specify the JRE used directly in your build.xml file. 您还可以尝试指定直接在build.xml文件中使用的JRE。

You can use source=1.5 and target=1.5 in javac ant task. 您可以在javac ant任务中使用source = 1.5和target = 1.5。 See here for details javac 看到这里的细节的javac

You need to explicitly specify the source and target in the build.xml: 您需要在build.xml中明确指定源和目标:

<property name="javac.source"  value="1.5"/>
<property name="javac.target"  value="1.5"/>
<javac source="${javac.source}"  target="${javac.target}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM