public static File exportProjectToJarFile(IProject project, boolean logInfo) { JarPackageData jarExportOps = new JarPackageData(); jarExportOps.setExportJavaFiles(false); jarExportOps.setExportClassFiles(true); jarExportOps.setIncludeDirectoryEntries(true); jarExportOps.setUsesManifest(false); jarExportOps.setOverwrite(true); jarExportOps.setJarBuilder(new LambdaFunctionJarBuilder()); try { Object[] elements = getElementsToExport(project); jarExportOps.setElements(elements); // prefix should be at least three characters long File jarFile = File.createTempFile(project.getName() + "-lambda", ".zip"); jarFile.deleteOnExit(); jarExportOps.setJarLocation(new Path(jarFile.getAbsolutePath())); if (logInfo) { LambdaPlugin.getDefault() .logInfo( String.format( "Exporting project [%s] to %s", project.getName(), jarFile.getAbsolutePath())); } IJarExportRunnable runnable = jarExportOps.createJarExportRunnable(null); runnable.run(null); if (logInfo) { LambdaPlugin.getDefault().logInfo("Project exported to " + jarFile.getAbsolutePath()); } return jarFile; } catch (Exception e) { LambdaPlugin.getDefault() .reportException( String.format("Unable to export project [%s] to jar file", project.getName()), e); return null; } }
private static Object[] getElementsToExport(IProject project) throws CoreException { IJavaProject javaProj = JavaCore.create(project); try { ILaunchConfiguration launchConfiguration = createLaunchConfigurationForProject(javaProj); return getSelectedElementsWithoutContainedChildren(launchConfiguration); } catch (CoreException e) { LambdaPlugin.getDefault() .warn("Unable to resolve dependencies of project " + project.getName(), e); // Fall back to export all the file resource inside the project return project.members(IResource.FILE); } }