ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conelly, Luis (PS, GNF, Contractor)" <Luis.Cone...@gnf.com>
Subject RE: Newbie; how to invoke an ant script from a GUI interface
Date Thu, 15 Jan 2004 14:54:43 GMT
shailesh

	Remove that line. I accidentally left it but it is not usefull at all.

	BTW, make sure you are setting the right paths for the lines:

	-----------------------------------------
	exec.setExecutable("/bin/ant.bat");
	exec.setDir(new java.io.File(""));
	Commandline.Argument arg = exec.createArg();
	arg.setLine("-buildfile /build.xml ");
	-----------------------------------------

	Regards.
	Luis
-----Original Message-----
From: Shailesh Sharma [mailto:shailesh_scea@yahoo.com]
Sent: Thursday, January 15, 2004 8:47 AM
To: Ant Users List
Subject: RE: Newbie; how to invoke an ant script from a GUI interface


Luis,
Iam using WLS 8.1 and iam using the ANT that comes along with it. The example that you gave
me doesn't seems to work for me as i doesn't have the package called:  
 
import com.borland.jbcl.layout.*;
 
 
what should i do ?
 
And i have set the classpath as:
c:\bea8.1\weblogic8.1\server\lib\ant\ant.jar
 
Please help.
 
-shailesh

"Conelly, Luis (PS, GNF, Contractor)" <Luis.Conelly@gnf.com> wrote:
Shalesh

I have tested following class. It is trully rudimentary, but it is a good place to start:

--------------------
package org.apache.tools.ant.antgui;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;

import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.Commandline;
import com.borland.jbcl.layout.*;

public class TestApplet extends Applet {
private boolean isStandalone = false;
TextArea textArea1 = new TextArea();
BorderLayout borderLayout1 = new BorderLayout();
Panel panel1 = new Panel();
BorderLayout borderLayout2 = new BorderLayout();
Button button1 = new Button();
Button button2 = new Button();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

//Construct the applet
public TestApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
textArea1.setEditable(false);
textArea1.setText("");
this.setVisible(true);
panel1.setForeground(Color.black);
panel1.setLayout(borderLayout2);
button1.setLabel("Execute");
button1.addActionListener(new TestApplet_button1_actionAdapter(this));
button1.addActionListener(new TestApplet_button1_actionAdapter(this));
button2.setLabel("Exit");
button2.addActionListener(new TestApplet_button2_actionAdapter(this));
this.add(textArea1, BorderLayout.CENTER);
this.add(panel1, BorderLayout.SOUTH);
panel1.add(button1, BorderLayout.WEST);
panel1.add(button2, BorderLayout.EAST);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}

public void runAnt() {
PrintStream ps = new PrintStream(new TaOutputStream());
Project project = new Project();
BuildLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(ps);
logger.setErrorPrintStream(ps);
logger.setEmacsMode(true);
project.addBuildListener(logger);
ExecTask exec = new ExecTask();
exec.setProject(project);
exec.setExecutable("/bin/ant.bat");
exec.setDir(new java.io.File("
"));
Commandline.Argument arg = exec.createArg();
arg.setLine("-buildfile 
/build.xml ");
exec.execute();
ps.flush();
}

//Main method
public static void main(String[] args) {
TestApplet applet = new TestApplet();
applet.isStandalone = true;
Frame frame;
frame = new Frame();
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height)
/ 2);
frame.setVisible(true);
}

void button1_actionPerformed(ActionEvent e) {
runAnt();
}

class TaOutputStream extends OutputStream {
TaOutputStream() {
super();
}
public void write(int b) throws IOException {
byte[] bytes = new byte[] {(byte) b};
String out = new String(bytes);
textArea1.append(out);
}
public void write(byte[] b, int off, int len) throws IOException {
String out = new String(b, off, len);
textArea1.append(out);
}
}

void button2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}

class TestApplet_button2_actionAdapter implements java.awt.event.ActionListener {
TestApplet adaptee;

TestApplet_button2_actionAdapter(TestApplet adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button2_actionPerformed(e);
}
}

class TestApplet_button1_actionAdapter implements java.awt.event.ActionListener {
TestApplet adaptee;

TestApplet_button1_actionAdapter(TestApplet adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}
--------------------

Of course you need the ant.jar file in your classpath to execute this class. It can be executed
as stand alone or in a web browser...

HTH
Luis


---------------------------------
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message