ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Newbie; how to invoke an ant script from a GUI interface
Date Thu, 15 Jan 2004 16:53:15 GMT
Conelly, Luis (PS, GNF, Contractor) wrote:

>Shailesh,
>
>If you remember, in the class I sent, I declared the package as:
>
>	package org.apache.tools.ant.antgui;
>
>but you declared the package as:
>
>	package parsing;
>
>I've been looking around the source code (ant 1.6) and I found that the setProject(Project)
method is public, but just in the abstract class org.apache.tools.ant.ProjectComponent, which
inherits to org.apache.tools.ant.Task and this inherits to org.apache.tools.ant.taskdefs.ExecTask.
When you are trying to access to this method from an outside package the compiler does not
allows you, since the method is not explicitely declared in Task or ExecTask classes.
>  
>
This is not correct,
a public method stays public when it is inherited, it does not need to
be made public again.

The code below compiles fine in ant 1.6 and 1.5.2 so there must be something
odd in the weblogic setup.

Peter

>My suggestion: change the package name
>
>--------------
>[1] http://www.site.uottawa.ca:4321/oose/index.html#protectedmethod
>[2] http://gcc.gnu.org/ml/java-prs/2000-q2/msg00238.html
>[3] http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html#62587
>	
>
>-----Original Message-----
>From: Shailesh Sharma [mailto:shailesh_scea@yahoo.com]
>Sent: Thursday, January 15, 2004 9:58 AM
>To: Ant Users List
>Subject: RE: Newbie; how to invoke an ant script from a GUI interface
>
>
>Luis,
>I have made the required changes as you directed but while compiling iam getting this
error:
> 
>setProject(org.apache.tools.ant.Project) is not public in org.apache.tools.ant.Task; cannot
be accesed from outside package
> 
>what is this problem and how can i solve it.
> 
>This is how my class looks like:
> 
> 
>package parsing;
>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("C:/bea8.1/weblogic81/server/bin/ant.bat");
>    exec.setDir(new java.io.File("c:/shailesh"));
>    Commandline.Argument arg = exec.createArg();
>    arg.setLine("-buildfile c:/shailesh/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);
>  }
>}
>
> 
> 
>please advise....thx, shailesh
>
>"Conelly, Luis (PS, GNF, Contractor)" <Luis.Conelly@gnf.com> wrote:
>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)" 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
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message