import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentExportDataModelProvider; import org.eclipse.jst.j2ee.web.datamodel.properties.IWebComponentExportDataModelProperties; import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; public class SomeClass{ /** * * @param projectName – Name of the web project * @param destinationPath – Destination path to create the war (eg: C:\temp\webapp.war) */ public void export(String projectName, String destinationPath) throws ExecutionException { IDataModel model = DataModelFactory.createDataModel(new WebComponentExportDataModelProvider()); model.setProperty(IWebComponentExportDataModelProperties.PROJECT_NAME,projectName); model.setProperty(IWebComponentExportDataModelProperties.ARCHIVE_DESTINATION, destinationPath); model.getDefaultOperation().execute( null, null ); } } Many thanx to http://www.eclipse.org/webtools/jst/components/j2ee/scenarios/WTPApis.html
Advertisements
Tags: build WAR programatically, create WAR programatically, Export dynamic web project, export WAR programatically, WAR export
May 24, 2012 at 6:26 am |
This was a great code snippet that I’ve been looking for a long time.
Whats the simplest way invoke it?
Is there a way to run this code without making a Eclipse plugin of it?
I tried to make an ANT task using the code and the invoking the ANT script using the JRE as the workspace but it seems that due to the architecture of OSGI all classes (JST and WST plugins) aren’t available in that classloader.
/Unlogic
December 5, 2012 at 6:11 pm |
Hi, thank’s for this code, but I can’t compile it, could you please give me the dependencies (refernece of the external jar involved) and the eclipse version compatible?