Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » How to use Eclipse Ant Task from Java Code
How to use Eclipse Ant Task from Java Code [message #68801] Wed, 22 July 2009 17:10 Go to next message
Miguel Angel Garcia de Dios is currently offline Miguel Angel Garcia de DiosFriend
Messages: 22
Registered: July 2009
Junior Member
Hi everyone,
I have spent lot of time trying to solve my problem and maybe you could
help me.
My question is quite simple: I have a build.xml file with some targets
ans tasks. Some of these tasks are Eclipse task, like:
eclipse.refreshLocal
qvto:transformation
jet.transform
My build.xml file is executed without problems if I launch it as
External Tool - Ant Build setting the "Run in the same JRE as the
workspace" property as usual.
The problem is when I want to launch my build.xml not from Java code
instead of from External Tool.

The code is below:

----------------------------------------------

private void execute() {
//Get written values
String preguiValue = (String)this.preguiCB.getSelectedItem();
String presecumlValue = (String)this.presecumlCB.getSelectedItem();
String roleValue = (String)this.roleCB.getSelectedItem();

Project project = new Project();
ByteArrayOutputStream out = null;
out = new ByteArrayOutputStream();
project.addBuildListener(UpdateModelsJFrame.createLogger( out ));
//project.setInputHandler(getProject().getInputHandler());
project.init();
File buildFile = new File("build.xml");
ProjectHelper.configureProject( project, buildFile);
project.setProperty("nameModel","PhoneBook2");
project.executeTarget("jet");

}


private static BuildLogger createLogger( ByteArrayOutputStream out ){
BuildLogger logger = null;
logger = new DefaultLogger();

logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(new PrintStream( out ));
logger.setErrorPrintStream(new PrintStream( out ));
logger.setEmacsMode(false);

return logger;
}

---------------------------------------------------


I get this error message:

---------------------------------------------------------

Exception in thread "AWT-EventQueue-0"
/home/miguel/eclipse/workspace/app.updatePreguiPresecModels/ build.xml:62:
Problem: failed to create task or type eclipse.refreshLocal
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

-----------------------------------------------------------
How con I set the classical "Run in the same JRE as the workspace"
property but programmatically?
In other words: How can I lunch my build.xml Ant file from Java code in
the same time this file can access to these task??

Thank you in advance!
Re: How to use Eclipse Ant Task from Java Code [message #68829 is a reply to message #68801] Wed, 22 July 2009 17:32 Go to previous messageGo to next message
Andrew Niefer is currently offline Andrew NieferFriend
Messages: 990
Registered: July 2009
Senior Member
You should look at org.eclipse.ant.core.AntRunner

As examples, you can look at
org.eclipse.pde.internal.core.exports.FeatureExportOperation #runScript
from org.eclipse.pde.core

Or
org.eclipse.pde.build.tests.PDETestCase#runAntScript
from org.eclipse.pde.build.tests

Both of these bundles are in cvs at
dev.eclipse.org:/cvsroot/eclipse/pde/ui/org.eclipse.pde.core
dev.eclipse.org:/cvsroot/eclipse/pde/build/org.eclipse.pde.b uild.tests

-Andrew
Miguel Angel Garcia de Dios wrote:
> Hi everyone,
> I have spent lot of time trying to solve my problem and maybe you could
> help me.
> My question is quite simple: I have a build.xml file with some targets
> ans tasks. Some of these tasks are Eclipse task, like:
> eclipse.refreshLocal
> qvto:transformation
> jet.transform
> My build.xml file is executed without problems if I launch it as
> External Tool - Ant Build setting the "Run in the same JRE as the
> workspace" property as usual.
> The problem is when I want to launch my build.xml not from Java code
> instead of from External Tool.
>
> The code is below:
>
> ----------------------------------------------
>
> private void execute() {
> //Get written values
> String preguiValue = (String)this.preguiCB.getSelectedItem();
> String presecumlValue = (String)this.presecumlCB.getSelectedItem();
> String roleValue = (String)this.roleCB.getSelectedItem();
>
> Project project = new Project();
> ByteArrayOutputStream out = null;
> out = new ByteArrayOutputStream();
> project.addBuildListener(UpdateModelsJFrame.createLogger( out ));
> //project.setInputHandler(getProject().getInputHandler());
> project.init();
> File buildFile = new File("build.xml");
> ProjectHelper.configureProject( project, buildFile);
> project.setProperty("nameModel","PhoneBook2");
> project.executeTarget("jet");
>
> }
>
>
> private static BuildLogger createLogger( ByteArrayOutputStream out ){
> BuildLogger logger = null;
> logger = new DefaultLogger();
>
> logger.setMessageOutputLevel(Project.MSG_INFO);
> logger.setOutputPrintStream(new PrintStream( out ));
> logger.setErrorPrintStream(new PrintStream( out ));
> logger.setEmacsMode(false);
>
> return logger;
> }
>
> ---------------------------------------------------
>
>
> I get this error message:
>
> ---------------------------------------------------------
>
> Exception in thread "AWT-EventQueue-0"
> /home/miguel/eclipse/workspace/app.updatePreguiPresecModels/ build.xml:62:
> Problem: failed to create task or type eclipse.refreshLocal
> Cause: The name is undefined.
> Action: Check the spelling.
> Action: Check that any custom tasks/types have been declared.
> Action: Check that any <presetdef>/<macrodef> declarations have taken
> place.
>
> -----------------------------------------------------------
> How con I set the classical "Run in the same JRE as the workspace"
> property but programmatically?
> In other words: How can I lunch my build.xml Ant file from Java code in
> the same time this file can access to these task??
>
> Thank you in advance!
Re: How to use Eclipse Ant Task from Java Code [message #559903 is a reply to message #68829] Mon, 20 September 2010 10:14 Go to previous messageGo to next message
Deepak Singla is currently offline Deepak SinglaFriend
Messages: 27
Registered: December 2009
Junior Member
eclipse.refreshLocal is used for resreshing your worksapce.

For eclipse.refreshLocal ant task Following may help you:

From the main menu select the Run -> External Tools -> Select External Tools again and then select your XML from under Ant Build. There are a series of tabs on the next menu including a scroll bar which you must select and scroll right until JRE appears. Then change the radion button to "Run in the same JRE as the workspace". That should do it.

This helped for me.

[Updated on: Mon, 20 September 2010 10:20]

Report message to a moderator

Re: How to use Eclipse Ant Task from Java Code [message #599818 is a reply to message #68801] Wed, 22 July 2009 17:32 Go to previous messageGo to next message
Andrew Niefer is currently offline Andrew NieferFriend
Messages: 990
Registered: July 2009
Senior Member
You should look at org.eclipse.ant.core.AntRunner

As examples, you can look at
org.eclipse.pde.internal.core.exports.FeatureExportOperation #runScript
from org.eclipse.pde.core

Or
org.eclipse.pde.build.tests.PDETestCase#runAntScript
from org.eclipse.pde.build.tests

Both of these bundles are in cvs at
dev.eclipse.org:/cvsroot/eclipse/pde/ui/org.eclipse.pde.core
dev.eclipse.org:/cvsroot/eclipse/pde/build/org.eclipse.pde.b uild.tests

-Andrew
Miguel Angel Garcia de Dios wrote:
> Hi everyone,
> I have spent lot of time trying to solve my problem and maybe you could
> help me.
> My question is quite simple: I have a build.xml file with some targets
> ans tasks. Some of these tasks are Eclipse task, like:
> eclipse.refreshLocal
> qvto:transformation
> jet.transform
> My build.xml file is executed without problems if I launch it as
> External Tool - Ant Build setting the "Run in the same JRE as the
> workspace" property as usual.
> The problem is when I want to launch my build.xml not from Java code
> instead of from External Tool.
>
> The code is below:
>
> ----------------------------------------------
>
> private void execute() {
> //Get written values
> String preguiValue = (String)this.preguiCB.getSelectedItem();
> String presecumlValue = (String)this.presecumlCB.getSelectedItem();
> String roleValue = (String)this.roleCB.getSelectedItem();
>
> Project project = new Project();
> ByteArrayOutputStream out = null;
> out = new ByteArrayOutputStream();
> project.addBuildListener(UpdateModelsJFrame.createLogger( out ));
> //project.setInputHandler(getProject().getInputHandler());
> project.init();
> File buildFile = new File("build.xml");
> ProjectHelper.configureProject( project, buildFile);
> project.setProperty("nameModel","PhoneBook2");
> project.executeTarget("jet");
>
> }
>
>
> private static BuildLogger createLogger( ByteArrayOutputStream out ){
> BuildLogger logger = null;
> logger = new DefaultLogger();
>
> logger.setMessageOutputLevel(Project.MSG_INFO);
> logger.setOutputPrintStream(new PrintStream( out ));
> logger.setErrorPrintStream(new PrintStream( out ));
> logger.setEmacsMode(false);
>
> return logger;
> }
>
> ---------------------------------------------------
>
>
> I get this error message:
>
> ---------------------------------------------------------
>
> Exception in thread "AWT-EventQueue-0"
> /home/miguel/eclipse/workspace/app.updatePreguiPresecModels/ build.xml:62:
> Problem: failed to create task or type eclipse.refreshLocal
> Cause: The name is undefined.
> Action: Check the spelling.
> Action: Check that any custom tasks/types have been declared.
> Action: Check that any <presetdef>/<macrodef> declarations have taken
> place.
>
> -----------------------------------------------------------
> How con I set the classical "Run in the same JRE as the workspace"
> property but programmatically?
> In other words: How can I lunch my build.xml Ant file from Java code in
> the same time this file can access to these task??
>
> Thank you in advance!
Re: How to use Eclipse Ant Task from Java Code [message #630042 is a reply to message #599818] Thu, 30 September 2010 13:32 Go to previous messageGo to next message
Julian P is currently offline Julian PFriend
Messages: 5
Registered: September 2010
Junior Member
Having the same problem, have you found a solution?

Regards,
Julian
Re: How to use Eclipse Ant Task from Java Code [message #1122070 is a reply to message #630042] Tue, 01 October 2013 07:47 Go to previous message
Shivakumar goniwada is currently offline Shivakumar goniwadaFriend
Messages: 28
Registered: August 2013
Junior Member
I having the same problem, anyone found the solution, please provide me if you found anything
Previous Topic:Project with multiple natures: Icon precedence?
Next Topic:menu visibleWhen
Goto Forum:
  


Current Time: Fri Mar 29 14:11:47 GMT 2024

Powered by FUDForum. Page generated in 0.08324 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top