This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Unable to compile java file through ant

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


I am getting the following exception while executing the ant script


Buildfile: build.xml
[echo] Compiling java file................
[echo] Closing java file................
[echo] Building MySrc.jar................
[echo] Closing MySrc.jar................

compile:
[javac] Compiling 1 source file to C:\AntBuild\ant\reddy
[javac] [parsing started C:\AntBuild\ant\reddy\Helloo.java]
[javac] [parsing completed 140ms]
[javac] [loading C:\Program Files\Java\jre1.5.0\lib\rt.jar(java/lang/Object.
class)]
[javac] C:\AntBuild\ant\reddy\Helloo.java:3: cannot access java.lang.Object
[javac] bad class file: C:\Program Files\Java\jre1.5.0\lib\rt.jar(java/lang/
Object.class)
[javac] class file has wrong version 49.0, should be 48.0
[javac] Please remove or make sure it appears in the correct subdirectory of
the classpath.
[javac] public static void main(String ll[])
[javac] ^
[javac] [total 5367ms]
[javac] 1 error

BUILD FAILED



I am enclosing the build.xml file too


Build.xml
-----------

<project name="MyTask" basedir="." default="compile">

<target name="clean" description="Delete all generated files">
<delete dir="classes"/>
<delete file="MySrc.jar"/>
</target>
<property name="debug.flag" value="off"/>


<echo>Compiling java file................</echo>

<target name="compile" description="Compiles the Task">
<javac srcdir="reddy" destdir="reddy" includes="**/*.java" verbose="true">
</javac>
</target>
<echo>Closing java file................</echo>

<echo>Building MySrc.jar................</echo>
<target name="jar" description="JARs the Task">
<jar destfile="MySrc.jar" basedir="reddy"/>
</target>
<echo>Closing MySrc.jar................</echo>
</project>






Can any one pls clarify the above error ...
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're asking a JDK 1.4 compiler to compile against the JDK 1.5 runtime classes, and it's refusing to do so. Check your CLASSPATH environment variable (which shouldn't include any copy of rt.jar) and check your build.properties file, if you have one.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see two issues in a quick look at your errors.

1. [loading C:\Program Files\Java\jre1.5.0\lib\rt.jar(java/lang/Object.
class)]

This is loading jar from the JRE (java runtime) instead of the jdk (includes tools).


2. [javac] class file has wrong version 49.0, should be 48.0

This complaint is JDK 1.4 (class version 48) indicating it is finding JDK1.5 classes (class version 49).
 
Greenhorn
Posts: 21
Mac Scala VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was bit by this for the second time in four year, but had forgotten the cause and fix.
The fix for Maven and Ant is to specify the source and target version.

For Ant it would be <javac ... source="1.4" target="1.4">

The Maven solution is left as an exercise for the student.
 
You can't expect to wield supreme executive power just because
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!