Learning Apache Ant, problems with Swing(?)  
Author Message
jg.campbell





PostPosted: 2004-7-8 20:08:00 Top

java-programmer, Learning Apache Ant, problems with Swing(?) I'm attempting to learn Apache Ant (apache-ant-1.6.1); OS Linux Fedora
Core 2; j2sdk1.4.2_04. I appear to have problems with Ant + Swing, but
each work separately.

The following is my first build file (copied from the web).

<?xml version="1.0"?>
<!-- build file for lesson 1 -->

<project name="tutorial" default="build" basedir=".">
<target name="build">
<javac srcdir="." />
</target>
</project>

Works fine on a simple Java program, e.g.

import java.io.*;
public class Hello {

public static void main(String args[]) {
System.out.println("Hello");
}
}

However, when I progress to anything involving Java Swing, I get
compilation errors like:

[javac] /home/jc/java/classes/anttest/GuiScreens.java: In method
`GuiScreens.main(java.lang.String[])':
[javac] /home/jc/java/classes/anttest/GuiScreens.java:24: error:
Can't find constructor
`javax.swing.JFrame(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)'
in type `javax.swing.JFrame'.
[javac] frame[j][i] = new JFrame("Config: " + i,
gc[i]);

/This program compiles okay using javac./

(BTW jc@localhost~/java/classes/anttest>$ echo $ANT_HOME
/usr/apache-ant-1.6.1
jc@localhost~/java/classes/anttest>$ echo $JAVA_HOME
/usr/java/j2sdk1.4.2_04)

Any ideas?

TIA,

Jon C.
 
Michael Cox





PostPosted: 2004-7-8 20:56:00 Top

java-programmer >> Learning Apache Ant, problems with Swing(?) > import java.io.*;
> public class Hello {
>
> public static void main(String args[]) {
> System.out.println("Hello");
> }
> }


Why import java.io.* for that?
You're not using it.
System.out is part of java.lang (which is automatically loaded).


> However, when I progress to anything involving Java Swing, I get
> compilation errors like:
>
> [javac] /home/jc/java/classes/anttest/GuiScreens.java: In method
> `GuiScreens.main(java.lang.String[])':
> [javac] /home/jc/java/classes/anttest/GuiScreens.java:24: error:
> Can't find constructor


Look in GuiScreens class and check spelling and parameters that are being
passed to the constructor.
Check it exists.



> `javax.swing.JFrame(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)'
> in type `javax.swing.JFrame'.
> [javac] frame[j][i] = new JFrame("Config: " + i,
> gc[i]);


Something wrong with the graphics configuration i'd guess?

hope that helps,
Michael


 
jg.campbell





PostPosted: 2004-7-9 2:53:00 Top

java-programmer >> Learning Apache Ant, problems with Swing(?) "Michael Cox" <email***@***.com> wrote in message news:<40ed445a$0$7800$email***@***.com>...
[...]
> > However, when I progress to anything involving Java Swing, I get
> > compilation errors like:
> >
> > [javac] /home/jc/java/classes/anttest/GuiScreens.java: In method
> > `GuiScreens.main(java.lang.String[])':
> > [javac] /home/jc/java/classes/anttest/GuiScreens.java:24: error:
> > Can't find constructor
>
>
> Look in GuiScreens class and check spelling and parameters that are being
> passed to the constructor.
> Check it exists.
>

See earlier in my message:

"/This program compiles okay using javac./". And it runs okay too.

Best regards,

Jon C.
 
 
jg.campbell





PostPosted: 2004-7-9 23:40:00 Top

java-programmer >> Learning Apache Ant, problems with Swing(?) email***@***.com (Jonathan G Campbell) wrote in message news:<email***@***.com>...
> I'm attempting to learn Apache Ant (apache-ant-1.6.1); OS Linux Fedora
> Core 2; j2sdk1.4.2_04. I appear to have problems with Ant + Swing, but
> each work separately.
>

> However, when I progress to anything involving Java Swing, I get
> compilation errors like:
>
> [javac] /home/jc/java/classes/anttest/GuiScreens.java: In method
> `GuiScreens.main(java.lang.String[])':
> [javac] /home/jc/java/classes/anttest/GuiScreens.java:24: error:
> Can't find constructor
> `javax.swing.JFrame(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)'
> in type `javax.swing.JFrame'.
> [javac] frame[j][i] = new JFrame("Config: " + i,
> gc[i]);
>
> /This program compiles okay using javac./
>
> (BTW jc@localhost~/java/classes/anttest>$ echo $ANT_HOME
> /usr/apache-ant-1.6.1
> jc@localhost~/java/classes/anttest>$ echo $JAVA_HOME
> /usr/java/j2sdk1.4.2_04)
>
> Any ideas?

Upon further (relatively incompetent) investigation, I find:

1. Ant is invoking gcj; and gcj has problems with Swing; (I know
there is a solution to that, but I'd prefer to go the javac route).

2. $ ant -version reports:

Apache Ant version 1.5.2-26 compiled on May 5 2004

So the RedHat installer had already installed Ant.

I suppose my immediate question is how to get Ant to use
/usr/java/j2sdk1.4.2_04/bin/javac ?

Best regards,

Jon C.
 
 
Tony Morris





PostPosted: 2004-7-10 14:40:00 Top

java-programmer >> Learning Apache Ant, problems with Swing(?) > I suppose my immediate question is how to get Ant to use
> /usr/java/j2sdk1.4.2_04/bin/javac ?

export $JAVA_HOME=/usr/java/j2sdk1.4.2_04/

It\s all there in the documentation.

--
Tony Morris
http://xdweb.net/~dibblego/


 
 
jg.campbell





PostPosted: 2004-7-10 17:52:00 Top

java-programmer >> Learning Apache Ant, problems with Swing(?) Sorry to bore the n.g. further, but I've solved the problem -- by
uninstalling the version of Ant (1.5.2-26) installed by RedHat; thus,
with Ant version 1.6.1, everything 'works'.

Best regards,

Jon C.