jst j2ee
WTP 1.5.x API’s unleashed
WTP LogoWTP Home
  By:
 

Neeraj Agrawal
Hari Shankar

Introduction
 
 

This article is the first in a series that provides a cheat sheet for WTP adopters to easily learn about specific WTP APIS.The APIs expostulated here will cover the following key J2EE operations:

  1. Project Creation
    • Web Project Creation
    • EJB Project Creation
    • EAR Project Creation
  2. J2EE Artifact Import/Export
    • EAR Import
    • EAR Export

 
Samples
 
 

So let us get started!

 
  • Web Project Creation
         IDataModel model = DataModelFactory.createDataModel(new WebFacetProjectCreationDataModelProvider());
         model.setProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, "WebTest1");
    
         FacetDataModelMap map = (FacetDataModelMap) model
            .getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP);
         IDataModel webModel = (IDataModel) map.get(IModuleConstants.JST_WEB_MODULE);
         webModel.setProperty(IJ2EEModuleFacetInstallDataModelProperties.FACET_VERSION_STR, "2.4");
         webModel.setBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.ADD_TO_EAR, true);
         model.getDefaultOperation().execute(new NullProgressMonitor(), null);
    			
  • Ejb Project Creation

         IDataModel model = DataModelFactory.createDataModel(new EjbFacetProjectCreationDataModelProvider());
         model.setProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, "EJBTest1");
    
         FacetDataModelMap map = (FacetDataModelMap) model
            .getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP);
         IDataModel ejbModel = (IDataModel) map.get(IModuleConstants.JST_EJB_MODULE);
         ejbModel.setProperty(IJ2EEModuleFacetInstallDataModelProperties.FACET_VERSION_STR, "2.1");
         ejbModel.setBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.ADD_TO_EAR, true);
         model.getDefaultOperation().execute(new NullProgressMonitor(), null);
    

  • EAR Project Creation
         IDataModel model = DataModelFactory.createDataModel(new EarFacetInstallDataModelProvider());
         model.setProperty(IFacetDataModelProperties.FACET_PROJECT_NAME, "FooEAR");
    		
         try {
             model.getDefaultOperation().execute( new NullProgressMonitor(), null);
         } catch (ExecutionException e) {
             e.printStackTrace();
         }
            
  • EAR Import
         IDataModel importModel = DataModelFactory.createDataModel( new EARComponentImportDataModelProvider());
    
         String earFile = "D:\\foo\\foo.ear";
         importModel.setProperty(IEARComponentImportDataModelProperties.FILE_NAME, earFile);
         try {
            importModel.getDefaultOperation().execute( new NullProgressMonitor(), null );
         } catch (ExecutionException e) {
             e.printStackTrace();
         }
    
    
    		
  • EAR Export
         String earOutputName = “c:\\foo\\foo.ear";
    
         IDataModel model = DataModelFactory.createDataModel(new	EARComponentExportDataModelProvider());
    
         model.setProperty(IEARComponentExportDataModelProperties.PROJECT_NAME,
         	  <EAR projectName>);
    	 model.setProperty(IEARComponentExportDataModelProperties.ARCHIVE_DESTINATION, 	earOutputName);
    
         try {
    	    model.getDefaultOperation().execute( null, null );
         } catch (ExecutionException e) {
              e.printStackTrace();
         }