从无头的Eclipse导出战争



如何用Java编程地从Eclipse .web项目导出WAR文件?

我有大问题战争 ant任务由于复杂的项目结构(ProjectX。web有一个依赖于ProjectX.java),我很困惑 WebComponentExportWizard 实现。

是否有WTP API可以使用?(像这个旧版本http://www.eclipse.org/webtools/jst/components/j2ee/api/j2ee_operationsAPI.html)

经过一番艰苦的战斗,我设法通过以下方法获得了war文件:

@SuppressWarnings("restriction")
public static void exportWar(IProject webProject) throws CoreException {
    WebComponentExportDataModelProvider modelProvider = new WebComponentExportDataModelProvider();
    IDataModel dataModel = DataModelFactory.createDataModel(modelProvider);
    dataModel.setBooleanProperty(IJ2EEComponentExportDataModelProperties.EXPORT_SOURCE_FILES, false);
    dataModel.setBooleanProperty(IJ2EEComponentExportDataModelProperties.OVERWRITE_EXISTING, true);
    dataModel.setStringProperty(IJ2EEComponentExportDataModelProperties.PROJECT_NAME, webProject.getName());
    dataModel.setStringProperty(IJ2EEComponentExportDataModelProperties.ARCHIVE_DESTINATION, webProject
            .getLocation().append(webProject.getName()).addFileExtension("war").toOSString());
    dataModel.setProperty(
            IJ2EEComponentExportDataModelProperties.COMPONENT,
            ComponentCore.createComponent(webProject));
    IDataModelOperation modelOperation = dataModel.getDefaultOperation();
    try {
        log.debug("Start  the export war operation");
        modelOperation.execute(null, null);
    }
    catch (ExecutionException e) {
        log.error("Error when exporting .war project", e);
    }
}

我使用org.eclipse.wst.server.core.util.PublishHelper.publishZip()如下,它为我工作。

IPath war = workDirectory.append("app.war");
PublishHelper publishHelper = new PublishHelper(null);
J2EEFlexProjDeployable deployable =
        new J2EEFlexProjDeployable(project, ComponentCore.createComponent(project));
publishHelper.publishZip(deployable.members(), war, null);

相关内容

  • 没有找到相关文章

最新更新