如何使用Java以编程方式从Eclipse .web项目导出WAR文件?
由于项目结构复杂,我的 war ant任务存在很大问题( ProjectX.web有一个来自ProjectX.java的依赖项,我很困惑 WebComponentExportWizard 实现。
是否有任何WTP API可供使用? (像这个旧版本http://www.eclipse.org/webtools/jst/components/j2ee/api/j2ee_operationsAPI.html)
答案 0 :(得分:2)
@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);
}
}
答案 1 :(得分:0)
我使用了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);