When I invoke java in bash, or in the Eclipse IDE it works as expected, however, when I invoke java with ant, the JPanel never becomes visible.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Paul_Wooten
Posted On:   Monday, September 15, 2008 11:11 PM

I've written two classes, one that extends JPanel, and the other which contains only the main method. If I add these two classes to a project in Eclipse, and then run the project as a Java Application, the JPanel is displayed. When I invoke java from bash, it behaves exactly the same as in the Eclipse IDE. However, when I invoke java using my ant build file, It never displays the JPanel. // class containing the main method package myPkg; import javax.swing.JFrame; import javax.swing.JPanel; public class myApp { public static void main(String[] args) { JFrame frame = new JFrame("My Frame!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myPanel panel = new m   More>>

I've written two classes, one that extends JPanel, and the other which contains only the main method. If I add these two classes to a project in Eclipse, and then run the project as a Java Application, the JPanel is displayed. When I invoke java from bash, it behaves exactly the same as in the Eclipse IDE. However, when I invoke java using my ant build file, It never displays the JPanel.


			
// class containing the main method
package myPkg;

import javax.swing.JFrame;
import javax.swing.JPanel;
public class myApp {

public static void main(String[] args) {

JFrame frame = new JFrame("My Frame!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myPanel panel = new myPanel();
frame.getContentPane().add(panel);
frame.pack();
frame.show();
System.out.println("!");
}
}

			
// class containing my JPanel
package myPkg;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JPanel;

public class myPanel extends JPanel {

public myPanel() {
setPreferredSize(new Dimension(400, 400));
setBackground(Color.white);
setVisible(true);
}
public void paintComponent(Graphics page)

{

super.paintComponent(page);

}
}


The target in my build file that executes java is:





Please keep in mind, I'm relatively new to ant, and I don't have much linux experience, although I'm fairly well versed in Java. My Ant Version is 1.7.0, and I'm developing in Ubuntu 8.04.1

Thank you    <<Less

Re: When I invoke java in bash, or in the Eclipse IDE it works as expected, however, when I invoke java with ant, the JPanel never becomes visible.

Posted By:   Robert_Lybarger  
Posted On:   Wednesday, September 17, 2008 08:07 PM

Ant is, somewhat unfortunately, a very fiddly tool. Handy once you finally get experience bending your desires to its odd behaviors, but always a bit fiddly. Probably the first (and likely only) thing I could advise in this case is to try the 'fork' attribute, a la Now granted, forking in other circumstances leads to other issues -- the ant script will continue running if you fork the exec, java, (etc) call and sometimes you don't want that to happen. If the fork doesn't help, then it'd be helpful to know what it might be complaining about, if anything. Run ant with the "-v" (verbose) flag to get a bit more junk pumping out on the console in hopes it helps you pin the issue down.
About | Sitemap | Contact