File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes eclipse, ant, and Java versions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "eclipse, ant, and Java versions" Watch "eclipse, ant, and Java versions" New topic
Author

eclipse, ant, and Java versions

Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
I've been working my way through the book _Eclipse in Action_, and have reached chapter 7, which involves (among other things) using java.net.URLEncoder and java.net.URLDecoder. I got these to work nicely yesterday morning. Then, yesterday afternoon, the compiler abruptly refused to compile the statements

answer = URLEncoder.encode (answer, "UTF-8");
and
answer = URLDecoder.decode (answer, "UTF-8");

According to the javadoc, these two-argument calls were introduced in Java 1.4, and the older one-argument calls are now deprecated. So I tried using one-argument calls instead, and the compiler liked them. Compiling the same source files from the command line invokes a 1.4 compiler, which likes the two-argument call and deprecates the one-argument call, as I would expect. So why is Eclipse suddenly using 1.3 libraries rather than 1.4 libraries? I checked "Window -> Preferences -> Java -> Compiler -> Compliance and Classfiles", and it says 1.4.

I thought perhaps the project file was corrupted somehow, so I started a new project, built the same directory structure, brought in the same libraries, and copied over the source files individually. Now everything compiles fine if I "save" individual source files, or if I "rebuild project", but if I use ant to compile the same files, it's 1.3 again. The ant code in question (basically copied from the _Eclipse in Action_ book) says
<target name="Compile"<br /> depends="-Init"<br /> description="Compile all Java classes">
<javac srcdir="${src}" destdir="${bin}">
<classpath>
<pathelement path="${java.class.path}"/>
<pathelement location="${junit_path}"/>
<pathelement location="${log4j_path}"/>
</classpath>
</javac>
<copy file="${logpropfile}" todir="${bin}"/>
<echo message="Compiled!"/>
</target>
This same ant code worked fine yesterday morning.

BTW, I'm using Eclipse 2.1, Java 1.4.1, MacOS 10.2.8. Eclipse 2.1 doesn't run on Java 1.4, only 1.3, but it explicitly allows you to compile and run Java 1.4 under its control. I would use a more up-to-date Eclipse, but it requires MacOS 10.3, and I'd rather not do that upgrade with 10.4 just around the corner.


SCJP 1.4
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Eclipse 2.1 works perfectly well with a 1.4 runtime and will generate 1.4 bytecode (I used the combo myself for over a year before converting to Eclipse 3).

You probably have set Eclipse to generate 1.3 bytecode.


42
Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
Actually, Eclipse <em>is</em> compiling things using 1.4 if I use "Rebuild Project" or "Rebuild All". It's only when I use ant that things revert to 1.3. As I mentioned before, when I compile with ant, the 1.4 calls are unrecognized and the 1.3 calls aren't deprecated.



I have since tried another experiment: compile with "Rebuild All" (which works), and then run my JUnit tests through ant. I got a ClassVersionNotSupportedException, exactly as one would expect from running 1.4 bytecode on a 1.3 JVM. Running the same JUnit tests directly from the menu with "Run As -> JUnit Test" works fine; again, Eclipse is using 1.4 but ant is using 1.3.



The obvious next experiment is to use ant from the command line, to see whether it's specifically "ant-called-from-Eclipse". I haven't tried that yet; I'll have to fiddle with search paths to get ant to run from the command line.
Stephen Bloch
Ranch Hand

Joined: Aug 19, 2003
Posts: 48
Let's try that ant code again, since it didn't display last time.
<pre>
<target name="Compile"
depends="-Init, -Prep"
description="Compile all Java classes">
<javac srcdir="${src}" destdir="${bin}">
<classpath>
<pathelement path="${java.class.path}"/>
<pathelement location="${junit_path}"/>
<pathelement location="${log4j_path}"/>
</classpath>
</javac>
<copy file="${logpropfile}" todir="${bin}"/>
<echo message="Compiled!"/>
</target>
</pre>

[ October 18, 2004: Message edited by: Stephen Bloch ]
[ October 18, 2004: Message edited by: Stephen Bloch ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: eclipse, ant, and Java versions
 
Similar Threads
How to set compliance level to 1.3
Problem in JDK compatibility
jvm version used by ant
Eclipse and Ant Problem
Ant: earExport is not working with Jdk 1.4