Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

How to specify jdk version in build.xml

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have hdk 1.4 as well as jdk 1.5 in my machine.

JAVA_HOME points to jdk 1.5

I need to compile my java code using jdk 1.4.

How could I specify in build.xml to use jdk1.4 for compiling my code?

Thanks
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option 1 : change the JAVA_HOME
If Ant has been compiled against 1.5 then you can modify the build task to

<javac source="1.4" target="1.4" ...>
...
</javac>
[ April 23, 2007: Message edited by: Purushothaman Thambu ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, Ant has handy properties ant.build.javac.target and ant.build.javac.source which you can use instead of setting these attributes explicitly.
 
Saloon Keeper
Posts: 25608
183
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use JAVA_HOME to specify which Java JDK you want to compile with.

Setting the "source" attribute merely tells the compiler what source restrictions apply. For example, setting 'source="1.3"' when using JDK 1.5's compiler should allow code with variables named "enum" to compile (enum is a reserved word in Java 1.5).

The "target" attribute likewise indicates what java level, the generated class files should be built for. One reason you'd set this is if you're building classes that will be serialized, since serialization isn't guaranteed across multiple runtime JVM versions. A major pain if you're doing RPC-style stuff.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Write the follwing javac target inside your "compile" target,

runtime-libs:: It will point your project lib directory. declared in properties.

<javac
bootclasspath="${runtime-libs}/rt.jar"
target="1.3"
source="1.3"
includeJavaRuntime="false"
includeAntRuntime="false"
debug="yes"
destdir="${build-dir}">
<classpath refid="project.class.path"/>
<src path="${code}"/>
</javac>

Thanks/Sirish
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic