warning during javac compilation by ant

526 views Asked by At

I have an ant build for my Java application. I'm forced to make my application be Java 1.6 compatible.

When I run my ant script I get the following warning:

[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6

Can you explain me what does it mean and what should I do to remove it? The code works fine, but I'm going to put it in production and I don't like to leave this kind of warnings unresolved.

My build.xml file looks like this:

<path id="master-classpath">
  <fileset dir="lib">
    <include name="*.jar"/>
  </fileset>
</path>

<target name="compile" depends="clean">
    <javac srcdir="src" destdir="${bin-dir}" debug="on" source="1.6" includeantruntime="false">
            <classpath refid="master-classpath"/>
    </javac>
</target>

<target name="clean">
    <mkdir dir="${bin-dir}"/>
    <mkdir dir="${build-dir}"/>

    <delete>
      <fileset dir="${bin-dir}"/>
      <fileset dir="${build-dir}"/>
    </delete>
</target>

Ant version: Ant(TM) version 1.8.2

Java version: javac 1.7.0_79

3

There are 3 answers

1
Tagir Valeev On BEST ANSWER

This means that although you are using -source option, you still have JDK 1.7 library, thus javac cannot guarantee that your code will work on Java 1.6. Javac will check whether you are not using new syntactic features (like try-with-resources operator), but it cannot check whether you are using new API methods (like java.nio.file.Files class). So even if it's compiled correctly, it may not work.

To my opinion the best solution is to compile with JDK 1.6. What warning suggests you is to provide the custom bootstrap class path which points on the installed JRE 1.6. So you can follow this advice if you have JRE 1.6, but don't want to run the whole build on JDK 1.6.

0
Paizo On

It is related to the javac. See https://blogs.oracle.com/darcy/entry/bootclasspath_older_source

To use javac from JDK N to cross-compiler to an older platform version, the correct practice is to:

  • Use the older -source setting.
  • Set the bootclasspath to compile against the rt.jar (or equivalent) for the older platform.
0
Brett Walker On

This has nothing to do with your source code or the ANT script you are running to build you application.

It has everything to do with how ANT itself is started. As you have stated you are running Ant using Java 1.7.0_79 There are significant API and library changes between Java 6 and Java 7. To avoid these differences and eliminate the warning you are seeing you need to run ANT in a Java 6 environment.