IPackageFragment pkgFragment= jProject.findPackageFragment(resource.getFullPath().removeLastSegments(1)); if (pkgFragment != null) { pkgRoot= JavaModelUtility.getPackageFragmentRoot(pkgFragment); if (pkgRoot != null) leadSegmentsToRemove= pkgRoot.getPath().segmentCount(); } } catch (JavaModelException ex) { addWarning("Java package could not be found for: " + resource.getFullPath(), ex);
isJavaElement= resource.getProject().hasNature(JavaCore.NATURE_ID); } catch (CoreException ex) { addWarning("Project nature could not be determined for: " + resource.getFullPath(), ex);
	protected void exportElement(Object element, IProgressMonitor progressMonitor) throws InterruptedException {		int leadSegmentsToRemove= 1;		IPackageFragmentRoot pkgRoot= null;		boolean isJavaElement= false;		IResource resource= null;		IJavaProject jProject= null;		if (element instanceof IJavaElement) {			isJavaElement= true;			IJavaElement je= (IJavaElement)element;			try {				resource= je.getUnderlyingResource();			} catch (JavaModelException ex) {				addWarning("Underlying resource not found for compilation unit: " + je.getElementName(), ex);				return;			}			jProject= je.getJavaProject();			pkgRoot= JavaModelUtility.getPackageFragmentRoot(je);			if (pkgRoot != null)				leadSegmentsToRemove= pkgRoot.getPath().segmentCount();		}		else			resource= (IResource)element;		if (!resource.isAccessible()) {			addWarning("Resource not found or not  accessible: " + resource.getFullPath(), null);			return;		}		if (resource.getType() == IResource.FILE) {			if (!resource.isLocal(IResource.DEPTH_ZERO))				try {					resource.setLocal(true , IResource.DEPTH_ZERO, progressMonitor);				} catch (CoreException ex) {					addWarning("Resource could not be retrieved locally: " + resource.getFullPath(), ex);					return;				}			/*			try {				isJavaProject= resource.getProject().hasNature(JavaCore.NATURE_ID);			} catch (CoreException ex) {				addWarning("Project nature could not be determined for: " + resource.getFullPath(), ex);				return;			}			if (isJavaProject) {				jProject= JavaCore.create(resource.getProject());				try {					IPackageFragment pkgFragment= jProject.findPackageFragment(resource.getFullPath().removeLastSegments(1));					if (pkgFragment != null) {						pkgRoot= JavaModelUtility.getPackageFragmentRoot(pkgFragment);						if (pkgRoot != null)							leadSegmentsToRemove= pkgRoot.getPath().segmentCount();					}				} catch (JavaModelException ex) {					addWarning("Java package could not be found for: " + resource.getFullPath(), ex);					return;				}			}			*/			IPath destinationPath= resource.getFullPath().removeFirstSegments(leadSegmentsToRemove);			progressMonitor.subTask(destinationPath.toString());						try {				// Binary Export				if (fJarPackage.areClassFilesExported() && isJavaElement && pkgRoot != null) {					// find corresponding file(s) on classpath and export					Iterator iter= filesOnClasspath((IFile)resource, destinationPath, jProject, progressMonitor);					IPath baseDestinationPath= destinationPath.removeLastSegments(1);					while (iter.hasNext()) {						IFile file= (IFile)iter.next();						if (!resource.isLocal(IResource.DEPTH_ZERO))													file.setLocal(true , IResource.DEPTH_ZERO, progressMonitor);						fJarWriter.write(file, baseDestinationPath.append(file.getName()));					}				}				// Java Files and resources				if (fJarPackage.areJavaFilesExported() && (!isJavaElement || isJavaFile(resource) || pkgRoot == null || !fJarPackage.areClassFilesExported()))					fJarWriter.write((IFile) resource, destinationPath);								} catch (IOException ex) {				String message= ex.getMessage() + " ";				if (message == null)					message= "IO Error exporting " + resource.getFullPath();				addWarning(message , ex);			} catch (CoreException ex) {				String message= ex.getMessage() + " ";				if (message == null)					message= "Core Error exporting " + resource.getFullPath();				addWarning(message, ex);			}			progressMonitor.worked(1);			ModalContext.checkCanceled(progressMonitor);		} else {			IResource[] children= null;			try {				children= ((IContainer) resource).members();			} catch (CoreException e) {				// this should never happen because an #isAccessible check is done before #members is invoked				addWarning("Error exporting " + resource.getFullPath(), e);			}			for (int i= 0; i < children.length; i++)				exportElement(children[i], progressMonitor);		}	}