Java Memorandum - How to make javac to reference user library BEFORE built-in library (rt.jar)

Here's the situation. I have a jar file, which is a library I need to use for an embedded Java application. Even though the embedded device only support Java 1.4, the library implements some 5.0 methods in org.w3c.dom.DOMImplementation. Because the same class is already in rt.jar for 1.4, just compiling a normal way doesn't work. It references the same class in rt.jar first and causes an compilation error. Here's the way to solve this...

Eclipse

There's a way to configure the order of build class path. Java Build Path --> Order and Export.

If I move up the customDOM.jar to the top, the compiler sees it first.

ANT

When building the same Java project using ANT, I needed to specify bootclasspath.

  <path id="compile.boot.path">
    <
fileset dir=".">
      <include
name="customDOM.jar" />
    </
fileset>
    <
fileset dir="${java.home}/lib">
      <include
name="rt.jar" />
    </
fileset>
  </
path>

  <
javac destdir="${build.classes.dir}"
       
debug="on"
       
deprecation="on"
       
optimize="off">
     <
bootclasspath refid="compile.boot.path" />
     <
classpath refid="compile.path" />
     <
src path="${project.src.dir}" />
     <
src path="${build.generated.dir}" />
     <include
name="**/*.java" />
  </
javac>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <code> <cite> <ul> <ol> <li> <dl> <dt> <dd> <p>
  • Lines and paragraphs break automatically.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.