jan.supol
jan.supol

Reputation: 2805

Use ant path as property in bootclasspath

In the ant script, I have path set:

<path id="classpath.id">
  <pathelement path="somepath_1" />
  ...
  <pathelement path="somepath_n" />
</path>

So that I use it in java task:

<java ... classpathref="classpath.id">
 ...
</java>

How do I use the classpath.id to set bootclasspath in java ant task similar to:

<java ...>
  <jvmarg value="-Xbootclasspath/a:${myjar.jar}${path.separator}${classpath.id}"/>
</java>

${classpath.id} is not known to the ant at this point.

Upvotes: 1

Views: 1299

Answers (2)

jan.supol
jan.supol

Reputation: 2805

For the sake of completeness, these are possible solutions:

Using ${ant.refid:} prefix

It's the cleanest solution and all the credit goes to martin clayton for pointing to this one. Just use

<java ...>
  <jvmarg value="Xbootclasspath/a:${myjar.jar}${path.separator}${ant.refid:classpath.id}"/>
</java>

Creating a new property

<property name="classpath.property" refid="classpath.id"/>
<java ...>
  <jvmarg value="Xbootclasspath/a:${myjar.jar}${path.separator}${classpath.property}"/>
</java>

Using bootclasspath and bootclasspathref

While bootclasspathref is available only to javac, bootclasspath can be nested in java:

<java fork="true" ...>
  <bootclasspath>
    <path refid="classpath.id"/>
    <pathelement path="${myjar.jar}" />
  </bootclasspath>
</java>

There are complications with this solution, though.

  • <bootclasspath> replaces the actual bootclasspath, removing java's jars from it, and there is no <bootclasspath/a> nested tag in ant so far.
  • In java SE 9, the -Xboothclasspath property is no longer available. There only is -Xboothclasspath/a, so <bootclasspath> does not work there.

Upvotes: 0

martin clayton
martin clayton

Reputation: 78135

There's a special syntax for getting the value of something referred to by an Ant reference id. Use ${ant.refid:classpath.id} instead of ${classpath.id}.

See Getting the value of a Reference with ${ant.refid:} for reference.

Upvotes: 2

Related Questions