• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

eclipse, ant, and Java versions

 
Stephen Bloch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephen Bloch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic