Eclipse Plugin : Programatically Export/Create/Build WAR file

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

Tags: , , , ,

2 Responses to “Eclipse Plugin : Programatically Export/Create/Build WAR file”

  1. Robert "Unlogic" Olofsson Says:

    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

  2. pp Says:

    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?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: