蚂蚁在使用不同的Java版本时会发生变化。

huangapple go评论71阅读模式
英文:

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.

&lt;property name=&quot;JAVA_VERSION&quot;  value=&quot;1.6&quot;/&gt;
&lt;property name=&quot;javahome&quot; location=&quot;C:\Java\jdk1.6.0_45&quot;/&gt;
&lt;property name=&quot;JAVA_HOME&quot; value=&quot;C:\Java\jdk1.6.0_45\&quot; /&gt;


&lt;path id=&quot;wls.classpath&quot;&gt;
		&lt;pathelement location=&quot;${JAVA_HOME}\lib\tools.jar&quot;/&gt;
	&lt;/path&gt;

&lt;target name=&quot;compile&quot; depends=&quot;prepare&quot; description=&quot;compile the Java source.&quot;&gt;
	&lt;echo message=&quot; java versoin is ${java.version}&quot; /&gt;
    &lt;javac debug=&quot;${debug}&quot; srcdir=&quot;./src&quot; destdir=&quot;./classes&quot; includeAntRuntime=&quot;false&quot; target=&quot;1.6&quot; source=&quot;1.6&quot;&gt;
      &lt;classpath refid=&quot;classpath&quot;/&gt;
    &lt;/javac&gt;
  &lt;/target&gt;

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=&quot;C:/java/jdk1.6.0_45&quot;
env.JDK_HOME=&quot;C:/java/jdk1.6.0_45&quot;

ant file

&lt;property environment=&quot;env&quot;/&gt;
&lt;property name=&quot;javahome&quot; location=&quot;${env.JAVA_HOME}&quot;/&gt;
&lt;property name=&quot;JAVA_HOME&quot; value=&quot;${env.JDK_HOME}&quot; /&gt;

huangapple
  • 本文由 发表于 2020年3月16日 20:42:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/60706232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定