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.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.ARCHIVE_DESTINATION, destinationPath);

model.getDefaultOperation().execute( null, null );


Many thanx to

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.


  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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: