Java メモ - javacで標準ライブラリの前にユーザーライブラリを参照させる方法

組み込みのJavaアプリであるライブラリを使わなければならない。そのライブラリはorg.w3c.dom.DOMImplementationを実装しているのだが、対応している環境はJava 1.4なのにそのクラスだけJava 5のメソッドを実装している。実行時にはこのjarファイルも使うのだけどコンパイル時には1.4の標準ライブラリが先に参照されてしまってエラーになる。このライブラリが標準ライブラリよりも先に参照される方法がこれ。

Eclipse

Java Build Path --> Order and Exportでライブラリの順序を指定。

customDOM.jarを一番上にしたらこちらがEclipse上では先に読まれるようになった。

ANT

同じことをANTでする場合は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.