英文:
Ant using different java version during
问题
我正试图在Java 1.6中编译一个项目。系统中的默认版本是1.7。我已经在build.xml中使用了以下属性,但它仍在使用Java 1.7。
<property name="JAVA_VERSION" value="1.6"/>
<property name="javahome" location="C:\Java\jdk1.6.0_45"/>
<property name="JAVA_HOME" value="C:\Java\jdk1.6.0_45\" />
<path id="wls.classpath">
<pathelement location="${JAVA_HOME}\lib\tools.jar"/>
</path>
<target name="compile" depends="prepare" description="compile the Java source.">
<echo message=" java version is ${java.version}" />
<javac debug="${debug}" srcdir="./src" destdir="./classes" includeAntRuntime="false" target="1.6" source="1.6">
<classpath refid="classpath"/>
</javac>
</target>
输出结果为:
compile:
[echo] java version is 1.7.0_221
[javac] Compiling 59 source files to C:\Jenkins\jobs\calcmanageronprem\branches\users-nageswar-k-b-test.g7m3im\workspace\CalcMgrCDF\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] Note: C:\Jenkins\jobs\calcmanageronprem\branches\users-nageswar-k-b-test.g7m3im\workspace\CalcMgrCDF\src\com\hyperion\planning\formula\TimeDate.java uses or overrides 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.
[javac] 1 warning
请帮助我使用Java版本1.6编译代码。
英文:
I am trying to compile a project in java 1.6. In system the default version is 1.7. I have used below properties in build.xml but still its using java 1.7.
<property name="JAVA_VERSION" value="1.6"/>
<property name="javahome" location="C:\Java\jdk1.6.0_45"/>
<property name="JAVA_HOME" value="C:\Java\jdk1.6.0_45\" />
<path id="wls.classpath">
<pathelement location="${JAVA_HOME}\lib\tools.jar"/>
</path>
<target name="compile" depends="prepare" description="compile the Java source.">
<echo message=" java versoin is ${java.version}" />
<javac debug="${debug}" srcdir="./src" destdir="./classes" includeAntRuntime="false" target="1.6" source="1.6">
<classpath refid="classpath"/>
</javac>
</target>
Output is :
compile:
[echo] java versoin is 1.7.0_221
[javac] Compiling 59 source files to C:\Jenkins\jobs\calcmanageronprem\branches\users-nageswar-k-b-test.g7m3im\workspace\CalcMgrCDF\classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
[javac] Note: C:\Jenkins\jobs\calcmanageronprem\branches\users-nageswar-k-b-test.g7m3im\workspace\CalcMgrCDF\src\com\hyperion\planning\formula\TimeDate.java uses or overrides 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.
[javac] 1 warning
Please help me in using java version 1.6 to compile the code
答案1
得分: 1
Properties in ant only assign values to variables. Setting environment variables in system needs to be done by either batch commands or if we are using jenkins then it should be done through jenkins file as mentioned below.
Jenkins file
env.JAVA_HOME="C:/java/jdk1.6.0_45"
env.JDK_HOME="C:/java/jdk1.6.0_45"
ant file
<property environment="env"/>
<property name="javahome" location="${env.JAVA_HOME}"/>
<property name="JAVA_HOME" value="${env.JDK_HOME}" />
英文:
Properties in ant only assign values to variables. Setting environment variables in system needs to be done by either batch commands or if we are using jenkins then it should be done through jenkins file as mentioned below.
Jenkins file
env.JAVA_HOME="C:/java/jdk1.6.0_45"
env.JDK_HOME="C:/java/jdk1.6.0_45"
ant file
<property environment="env"/>
<property name="javahome" location="${env.JAVA_HOME}"/>
<property name="JAVA_HOME" value="${env.JDK_HOME}" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论