List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.jst.j2ee.project.facet.AppClientFacetInstallDelegate.java
License:Open Source License
protected IVirtualComponent createFlexibleProject(IProgressMonitor monitor, IProject project, IDataModel model, IJavaProject jproj, IProjectFacetVersion fv) throws Exception { // Create the directory structure. final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IPath pjpath = project.getFullPath(); final IVirtualComponent c = ComponentCore.createComponent(project, false); c.create(0, null);/*from www . j a v a2s .c o m*/ setOutputFolder(model, c); final IVirtualFolder root = c.getRootFolder(); IFolder sourceFolder = null; String configFolder = null; configFolder = model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER); Path configFolderPath = new Path(configFolder); root.createLink(configFolderPath, 0, null); J2EEModuleVirtualComponent.setDefaultDeploymentDescriptorFolder(root, configFolderPath, null); String configFolderName = model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER); IPath configFolderpath = pjpath.append(configFolderName); sourceFolder = ws.getRoot().getFolder(configFolderpath); if (fv == IJ2EEFacetConstants.APPLICATION_CLIENT_70 || fv == IJ2EEFacetConstants.APPLICATION_CLIENT_60 || fv == IJ2EEFacetConstants.APPLICATION_CLIENT_50) { if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) { // Create the deployment descriptor (application-client.xml) if one doesn't exist IFile appClientFile = sourceFolder.getFile(new Path(J2EEConstants.APP_CLIENT_DD_URI)); if (!appClientFile.exists()) { try { if (!appClientFile.getParent().exists() && (appClientFile.getParent().getType() == IResource.FOLDER)) { ((IFolder) appClientFile.getParent()).create(true, true, monitor); } String appClientXmlContents = null; if (fv == IJ2EEFacetConstants.APPLICATION_CLIENT_70) { appClientXmlContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application-client version=\"7\" xmlns=\"http://xmlns.jcp.org/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application-client_7.xsd\">\n <display-name>" //$NON-NLS-1$ + XMLWriter.getEscaped(project.getName()) + "</display-name> \n </application-client>"; //$NON-NLS-1$ } else if (fv == IJ2EEFacetConstants.APPLICATION_CLIENT_60) { appClientXmlContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application-client version=\"6\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application-client_6.xsd\">\n <display-name>" //$NON-NLS-1$ + XMLWriter.getEscaped(project.getName()) + "</display-name> \n </application-client>"; //$NON-NLS-1$ } else { appClientXmlContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<application-client version=\"5\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application-client_5.xsd\">\n <display-name>" //$NON-NLS-1$ + XMLWriter.getEscaped(project.getName()) + "</display-name> \n </application-client>"; //$NON-NLS-1$ } appClientFile.create(new ByteArrayInputStream(appClientXmlContents.getBytes("UTF-8")), true, //$NON-NLS-1$ monitor); } catch (UnsupportedEncodingException e) { J2EEPlugin.logError(e); } } } } else { if (!sourceFolder.getFile(J2EEConstants.APP_CLIENT_DD_URI).exists()) { String ver = model.getStringProperty(IFacetDataModelProperties.FACET_VERSION_STR); int nVer = J2EEVersionUtil.convertVersionStringToInt(ver); AppClientArtifactEdit.createDeploymentDescriptor(project, nVer); } } // add source folder maps final IClasspathEntry[] cp = jproj.getRawClasspath(); for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { root.createLink(cpe.getPath().removeFirstSegments(1), 0, null); } } return c; }
From source file:org.eclipse.jst.j2ee.project.facet.UtilityFacetInstallDelegate.java
License:Open Source License
public void execute(final IProject project, final IProjectFacetVersion fv, final Object cfg, final IProgressMonitor monitor) throws CoreException { if (monitor != null) { monitor.beginTask("", 1); //$NON-NLS-1$ }/*w w w . j a v a 2 s . c om*/ try { final IDataModel model = (IDataModel) cfg; // Add WTP natures. WtpUtils.addNatures(project); // Setup the flexible project structure. final IVirtualComponent c = ComponentCore.createComponent(project, false); c.create(0, null); final IVirtualFolder jsrc = c.getRootFolder(); final IJavaProject jproj = JavaCore.create(project); final IClasspathEntry[] cp = jproj.getRawClasspath(); for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = cpe.getPath().removeFirstSegments(1); if (path.isEmpty()) { path = new Path("/"); //$NON-NLS-1$ } jsrc.createLink(path, 0, null); } } // final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IVirtualFolder root = c.getRootFolder(); IContainer container = null; if (root.getProjectRelativePath().segmentCount() == 0) { container = project; } else { container = project.getFolder(root.getProjectRelativePath()); } try { if (container != null) createManifest(project, container, monitor); } catch (InvocationTargetException e) { J2EEPlugin.logError(e); } catch (InterruptedException e) { J2EEPlugin.logError(e); } ClasspathHelper.removeClasspathEntries(project, fv); if (!ClasspathHelper.addClasspathEntries(project, fv)) { // TODO: Support the no runtime case. // ClasspathHelper.addClasspathEntries( project, fv, <something> ); } if (model.getBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.INSTALL_EAR_LIBRARY)) { final IPath earLibContainer = new Path(J2EEComponentClasspathContainer.CONTAINER_ID); addToClasspath(jproj, JavaCore.newContainerEntry(earLibContainer)); } try { ((IDataModelOperation) model.getProperty(FacetDataModelProvider.NOTIFICATION_OPERATION)) .execute(monitor, null); } catch (ExecutionException e) { J2EEPlugin.logError(e); } if (monitor != null) { monitor.worked(1); } } catch (Exception e) { J2EEPlugin.logError(e); } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.eclipse.jst.j2ee.refactor.listeners.J2EEElementChangedListener.java
License:Open Source License
protected static List<IPath> getSourceFolders(IProject project) { IJavaProject javaProj = JavaCore.create(project); if (javaProj == null) return null; if (!javaProj.exists()) return null; IClasspathEntry[] cp = null;//from w ww . j av a 2 s. c o m try { cp = javaProj.getRawClasspath(); } catch (JavaModelException ex) { J2EEPlugin.logError(ex); return null; } List sourcePaths = new ArrayList(); for (int i = 0; i < cp.length; i++) { if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourcePaths.add(cp[i].getPath().removeFirstSegments(1)); } } return sourcePaths; }
From source file:org.eclipse.jst.j2ee.web.project.facet.WebFacetInstallDelegate.java
License:Open Source License
public void execute(final IProject project, final IProjectFacetVersion fv, final Object cfg, final IProgressMonitor monitor) throws CoreException { if (monitor != null) { monitor.beginTask("", 1); //$NON-NLS-1$ }//w w w . j a v a 2 s. c om try { final IDataModel model = (IDataModel) cfg; final IJavaProject jproj = JavaCore.create(project); // Add WTP natures. WtpUtils.addNatures(project); // Create the directory structure. final IWorkspace ws = ResourcesPlugin.getWorkspace(); final IPath pjpath = project.getFullPath(); final IPath contentdir = setContentPropertyIfNeeded(model, pjpath, project); mkdirs(ws.getRoot().getFolder(contentdir)); final IPath webinf = contentdir.append("WEB-INF"); //$NON-NLS-1$ IFolder webinfFolder = ws.getRoot().getFolder(webinf); mkdirs(webinfFolder); final IPath webinflib = webinf.append("lib"); //$NON-NLS-1$ mkdirs(ws.getRoot().getFolder(webinflib)); // Setup the flexible project structure. final IVirtualComponent c = ComponentCore.createComponent(project, false); c.create(0, null); String contextRoot = model.getStringProperty(IWebFacetInstallDataModelProperties.CONTEXT_ROOT); setContextRootPropertyIfNeeded(c, contextRoot); setOutputFolder(model, c); final IVirtualFolder webroot = c.getRootFolder(); if (webroot.getProjectRelativePath().equals(new Path("/"))) { //$NON-NLS-1$ Path configFolderPath = new Path( model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER)); webroot.createLink(configFolderPath, 0, null); J2EEModuleVirtualComponent.setDefaultDeploymentDescriptorFolder(webroot, configFolderPath, null); } if (fv == WebFacetUtils.WEB_31) { if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) { createWeb31DeploymentDescriptor(project, fv, webinfFolder, monitor); } } else if (fv == WebFacetUtils.WEB_30) { if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) { createWeb30DeploymentDescriptor(project, fv, webinfFolder, monitor); } } else if (fv == WebFacetUtils.WEB_25) { if (model.getBooleanProperty(IJ2EEFacetInstallDataModelProperties.GENERATE_DD)) { createWeb25DeploymentDescriptor(project, fv, webinfFolder, monitor); } } else { // Create the deployment descriptor (web.xml) if one doesn't exist if (!webinfFolder.getFile("web.xml").exists()) { //$NON-NLS-1$ String ver = fv.getVersionString(); int nVer = J2EEVersionUtil.convertVersionStringToInt(ver); WebArtifactEdit.createDeploymentDescriptor(project, nVer); } } // Set entries for src folders final IVirtualFolder jsrc = c.getRootFolder().getFolder("/WEB-INF/classes"); //$NON-NLS-1$ final IClasspathEntry[] cp = jproj.getRawClasspath(); for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (cpe.getPath().removeFirstSegments(1).segmentCount() > 0) { try { IFolder srcFolder = ws.getRoot().getFolder(cpe.getPath()); IVirtualResource[] virtualResource = ComponentCore.createResources(srcFolder); //create link for source folder only when it is not mapped if (virtualResource.length == 0) { jsrc.createLink(cpe.getPath().removeFirstSegments(1), 0, null); } } catch (Exception e) { WebPlugin.logError(e); } } } } IVirtualFile vf = c.getRootFolder().getFile(new Path(J2EEConstants.MANIFEST_URI)); IFile manifestmf = vf.getUnderlyingFile(); if (manifestmf == null || !manifestmf.exists()) { try { createManifest(project, c.getRootFolder().getUnderlyingFolder(), monitor); } catch (InvocationTargetException e) { WebPlugin.logError(e); } catch (InterruptedException e) { WebPlugin.logError(e); } } // Setup the classpath. ClasspathHelper.removeClasspathEntries(project, fv); if (!ClasspathHelper.addClasspathEntries(project, fv)) { // TODO: Support the no runtime case. // ClasspathHelper.addClasspathEntries( project, fv, <something> ); } // Add the web libraries container. if (model.getBooleanProperty(IWebFacetInstallDataModelProperties.INSTALL_WEB_LIBRARY)) { final IPath webLibContainer = new Path(WebAppLibrariesContainer.CONTAINER_ID); addToClasspath(jproj, JavaCore.newContainerEntry(webLibContainer)); } if (model.getBooleanProperty(IJ2EEModuleFacetInstallDataModelProperties.INSTALL_EAR_LIBRARY)) { final IPath earLibContainer = new Path(J2EEComponentClasspathContainer.CONTAINER_ID); addToClasspath(jproj, JavaCore.newContainerEntry(earLibContainer)); } try { ((IDataModelOperation) model.getProperty(FacetDataModelProvider.NOTIFICATION_OPERATION)) .execute(monitor, null); } catch (ExecutionException e) { WebPlugin.logError(e); } if (monitor != null) { monitor.worked(1); } } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.eclipse.jst.j2ee.web.project.facet.WebFragmentFacetInstallDataModelProvider.java
License:Open Source License
@Override public Object getDefaultProperty(String propertyName) { if (propertyName.equals(CONTENT_DIR)) { return ""; //$NON-NLS-1$ } else if (propertyName.equals(FACET_ID)) { return WEBFRAGMENT; } else if (propertyName.equals(ADD_TO_EAR)) { return false; } else if (propertyName.equals(ADD_TO_WAR)) { return true; } else if (propertyName.equals(MODULE_URI)) { String projectName = model.getStringProperty(FACET_PROJECT_NAME).replace(' ', '_'); return projectName + IJ2EEModuleConstants.JAR_EXT; } else if (propertyName.equals(ADD_TO_WAR)) { return new Boolean(J2EEPlugin.getDefault().getJ2EEPreferences() .getBoolean(J2EEPreferences.Keys.ADD_TO_EAR_BY_DEFAULT) && isWARSupportedByRuntime()); } else if (propertyName.equals(WAR_PROJECT_NAME)) { if (model.isPropertySet(LAST_WAR_NAME)) { IProject project = ProjectUtilities.getProject(getStringProperty(LAST_WAR_NAME)); if (project.exists() && project.isAccessible()) return project.getName(); }//from w w w . j ava 2s . c o m DataModelPropertyDescriptor[] descs = getValidPropertyDescriptors(WAR_PROJECT_NAME); if (descs.length > 0) { DataModelPropertyDescriptor desc = descs[0]; String eARName = desc.getPropertyDescription(); if (eARName != null && !eARName.equals("")) { //$NON-NLS-1$ return eARName; } return getDataModel().getStringProperty(FACET_PROJECT_NAME) + "WAR"; //$NON-NLS-1$ } return getDataModel().getStringProperty(FACET_PROJECT_NAME) + "WAR"; //$NON-NLS-1$ } else if (propertyName.equals(CONFIG_FOLDER)) { // Return the first source folder found in the java facet install config or // the first source folder defined in the classpath final IFacetedProjectWorkingCopy localFpjwc = (IFacetedProjectWorkingCopy) getProperty( FACETED_PROJECT_WORKING_COPY); if (this.javaFacetInstallConfig != null) { final List<IPath> sourceFolders = this.javaFacetInstallConfig.getSourceFolders(); if (!sourceFolders.isEmpty()) { return sourceFolders.get(0).toPortableString(); } } else { final IFacetedProject fpj = localFpjwc.getFacetedProject(); if (fpj.hasProjectFacet(JavaFacet.FACET)) { try { final IJavaProject jpj = JavaCore.create(fpj.getProject()); for (IClasspathEntry cpe : jpj.getRawClasspath()) { if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { return cpe.getPath().removeFirstSegments(1).toPortableString(); } } } catch (CoreException e) { WebPlugin.logError(e); } } } } return super.getDefaultProperty(propertyName); }
From source file:org.eclipse.jst.j2ee.web.project.facet.WebFragmentFacetInstallDelegate.java
License:Open Source License
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException { if (monitor != null) monitor.beginTask("", 1); //$NON-NLS-1$ try {/*from w ww. j a va2 s . c o m*/ IDataModel model = (IDataModel) config; WtpUtils.addNatures(project); final IVirtualComponent c = ComponentCore.createComponent(project, false); c.create(0, null); final IVirtualFolder jsrc = c.getRootFolder(); final IJavaProject jproj = JavaCore.create(project); final IClasspathEntry[] cp = jproj.getRawClasspath(); IPath firstPath = null; for (int i = 0; i < cp.length; i++) { final IClasspathEntry cpe = cp[i]; if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = cpe.getPath().removeFirstSegments(1); if (path.isEmpty()) { path = new Path("/"); //$NON-NLS-1$ } jsrc.createLink(path, 0, null); if (firstPath == null) { firstPath = path; } } } J2EEModuleVirtualComponent.setDefaultDeploymentDescriptorFolder(jsrc, firstPath, null); final IVirtualFolder root = c.getRootFolder(); IContainer container = null; if (root.getProjectRelativePath().segmentCount() == 0) { container = project; } else { container = root.getUnderlyingFolder(); } try { if (container != null) { createWebFragmentFile(project, fv, container, monitor); createManifest(project, container, monitor); } } catch (InvocationTargetException e) { J2EEPlugin.logError(e); } catch (InterruptedException e) { J2EEPlugin.logError(e); } ClasspathHelper.removeClasspathEntries(project, fv); if (!ClasspathHelper.addClasspathEntries(project, fv)) { // TODO: Support the no runtime case. // ClasspathHelper.addClasspathEntries( project, fv, <something> ); } try { ((IDataModelOperation) model.getProperty(FacetDataModelProvider.NOTIFICATION_OPERATION)) .execute(monitor, null); } catch (ExecutionException e) { WebPlugin.logError(e); } } finally { if (monitor != null) monitor.done(); } }
From source file:org.eclipse.jst.jsf.core.internal.tld.LoadBundleUtil.java
License:Open Source License
private static IFile getSourceFile(IJavaProject javaProject, String baseName) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { final IFile file = getFile(javaProject, baseName, classpathEntries, i); if (file.exists()) { return file; }/*from w w w .j a v a2 s.c o m*/ } else if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(classpathEntries[i].getPath().toString()); IJavaProject javaProject3 = JavaCore.create(project); final IFile file = getSourceFile(javaProject3, baseName); if (file != null && file.exists()) { return file; } } else if (classpathEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && classpathEntries[i] .getPath().equals(new Path("org.eclipse.jst.j2ee.internal.module.container"))) //$NON-NLS-1$ { IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntries[i].getPath(), javaProject); IClasspathEntry[] classpathEntries2 = container.getClasspathEntries(); for (int j = 0; j < classpathEntries2.length; j++) { if (classpathEntries2[j].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(classpathEntries2[j].getPath().toString()); IJavaProject javaProject3 = JavaCore.create(project); final IFile file = getSourceFile(javaProject3, baseName); if (file != null && file.exists()) { return file; } } } } } return null; }
From source file:org.eclipse.jst.jsf.core.jsfappconfig.AnnotationPackageFragmentRoot.java
License:Open Source License
private final boolean isWebInfClasses(IPackageFragmentRoot root_) { IClasspathEntry cpe;/* ww w. j av a 2 s. c o m*/ try { cpe = root_.getResolvedClasspathEntry(); // IPath rootPath = cpe.getOutputLocation(); return cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE; // if (rootPath == null) { // rootPath = jProject.getOutputLocation(); // } // return webInfClassesPath.equals(rootPath); } catch (JavaModelException e) { return false; } }
From source file:org.eclipse.jst.jsp.core.taglib.ProjectDescription.java
License:Open Source License
/** * @param entry/* w ww . j a v a2 s .c om*/ */ private void indexClasspath(IClasspathEntry entry) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: { IClasspathContainer container = (IClasspathContainer) entry; IClasspathEntry[] containedEntries = container.getClasspathEntries(); for (int i = 0; i < containedEntries.length; i++) { indexClasspath(containedEntries[i]); } } break; case IClasspathEntry.CPE_LIBRARY: { /* * Ignore libs in required projects that are not exported */ IPath libPath = entry.getPath(); if (!fClasspathJars.containsKey(libPath.toString())) { final File file = libPath.toFile(); if (file.exists()) { if (file.isDirectory()) { indexDirectory(file, entry.isExported()); } else { updateClasspathLibrary(libPath.toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else { /* * Note: .jars on the classpath inside of the project * will have duplicate entries in the JAR references * table that will e returned to * getAvailableTaglibRecords(). */ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(libPath); if (resource != null && resource.isAccessible()) { if (resource.getType() == IResource.FILE) { if (resource.getLocation() != null) { updateClasspathLibrary(resource.getLocation().toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else if (resource.getType() == IResource.FOLDER) { try { resource.accept(new Indexer(), 0); } catch (CoreException e) { Logger.logException(e); } } } } } } break; case IClasspathEntry.CPE_PROJECT: { /* * We're currently ignoring whether the project exports all of * its build path */ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); if (project != null) { fClasspathProjects.add(project); } } break; case IClasspathEntry.CPE_SOURCE: { IPath path = entry.getPath(); try { IResource sourceFolder = ResourcesPlugin.getWorkspace().getRoot().findMember(path); // could be a bad .classpath file if (sourceFolder != null) { sourceFolder.accept(new Indexer(), 0); } } catch (CoreException e) { Logger.logException(e); } } break; case IClasspathEntry.CPE_VARIABLE: { IPath libPath = JavaCore.getResolvedVariablePath(entry.getPath()); if (libPath != null) { File file = libPath.toFile(); // file in filesystem if (file.exists() && !file.isDirectory()) { updateClasspathLibrary(libPath.toString(), ITaglibRecordEvent.ADDED, entry.isExported()); } else { // workspace file IFile jarFile = ResourcesPlugin.getWorkspace().getRoot().getFile(libPath); if (jarFile.isAccessible() && jarFile.getType() == IResource.FILE && jarFile.getLocation() != null) { String jarPathString = jarFile.getLocation().toString(); updateClasspathLibrary(jarPathString, ITaglibRecordEvent.ADDED, entry.isExported()); } } } } break; } }
From source file:org.eclipse.jst.pagedesigner.jsf.ui.converter.operations.jsf.LoadBundleOperation.java
License:Open Source License
/** * Find specified file in any source folder of the specified project. * //www . j a v a 2 s . co m * @param project IProject instance. * @param filePath Source folder-relative path of the file to be located. * @return the specified file in any source folder of the specified project. */ protected IResource findFileInSrcFolder(IProject project, String filePath) { IResource resource = null; IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { try { IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true); for (int i = 0; i < classpathEntries.length; i++) { IClasspathEntry classpathEntry = classpathEntries[i]; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath srcPath = classpathEntry.getPath(); //srcPath = srcPath.removeFirstSegments(srcPath.matchingFirstSegments(project.getFullPath())); IPath srcFilePath = srcPath.append(filePath); IResource tmpResource = project.getParent().findMember(srcFilePath); if (tmpResource != null) { resource = tmpResource; break; } } } } catch (JavaModelException jme) { //ignore - returning null from method will indicate failure } } return resource; }