Java Code Examples for org.eclipse.jdt.launching.JavaRuntime#computeDefaultRuntimeClassPath()

The following examples show how to use org.eclipse.jdt.launching.JavaRuntime#computeDefaultRuntimeClassPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DocumentUimaImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the project class loader.
 *
 * @param project the project
 * @return the project class loader
 * @throws CoreException the core exception
 */
public static ClassLoader getProjectClassLoader(IProject project) throws CoreException {
  IProjectNature javaNature = project.getNature(JAVA_NATURE);
  if (javaNature != null) {
    JavaProject javaProject = (JavaProject) JavaCore.create(project);
    
    String[] runtimeClassPath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    List<URL> urls = new ArrayList<>();
    for (String cp : runtimeClassPath) {
      try {
        urls.add(Paths.get(cp).toUri().toURL());
      } catch (MalformedURLException e) {
        CasEditorPlugin.log(e);
      }
    }
    return new URLClassLoader(urls.toArray(new URL[0]));
  } 
  return null;
}
 
Example 2
Source File: RuntimeClasspathEntryResolver.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Expand out the list of dependencies for a given IJavaProject.
 */
private List<IRuntimeClasspathEntry> dependenciesForProject(IJavaProject project)
    throws CoreException {
  ArrayList<IRuntimeClasspathEntry> out = new ArrayList<IRuntimeClasspathEntry>();
  String[] deps = JavaRuntime.computeDefaultRuntimeClassPath(project);

  for (String dep : deps) {
    IRuntimeClasspathEntry cpEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(dep));
    out.add(cpEntry);
  }

  return out;
}
 
Example 3
Source File: GwtSdk.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a {@link ClassLoader} that is backed by the project's runtime classpath.
 *
 * TODO: This returns a classloader which contains ALL of the jars of the project. Lookups on this
 * thing are going to be SLOW. Can we optimize this? We could create a classloader that just
 * contains the jars that GWT requires. Maybe caching is the right solution here.
 *
 * TODO: Why can't we just delegate to {@link #getClasspathEntries()} when generating the
 * classloader URLs? Why do we have to add every URL that is part of the project? That would
 * certainly speed up lookups on this classloader. Maybe we cannot do this because project-bound
 * sdks handle the case of source-based runtimes, and in that case, we need all of the dependencies
 * as part of the classloader.
 */
@Override
public URLClassLoader createClassLoader() throws SdkException, MalformedURLException {
  try {
    String[] defaultRuntimeClasspath = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
    URL[] urls = new URL[defaultRuntimeClasspath.length];
    for (int i = 0; i < defaultRuntimeClasspath.length; ++i) {
      File file = new File(defaultRuntimeClasspath[i]);
      urls[i] = file.toURI().toURL();
    }
    return new URLClassLoader(urls);
  } catch (CoreException e) {
    throw new SdkException(e);
  }
}
 
Example 4
Source File: ClassLoaderProvider.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a ClassLoader for the Project attached to the parent.
 * @param project
 * @param parent
 * @return
 */
public static URLClassLoader getClassLoaderForProject(IProject project, ClassLoader parent){
	String[] classPathEntries;
	
	try{
		IJavaProject javaproject = JavaCore.create(project);
		classPathEntries = JavaRuntime.computeDefaultRuntimeClassPath(javaproject);
	}catch(CoreException e){
		classPathEntries = new String[]{};
	}
	
	URL[] urls = getClassPathEntyUrls(classPathEntries);
	URLClassLoader classLoader  = new  URLClassLoader(urls, parent);
	return classLoader;
}
 
Example 5
Source File: JavadocTreeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath[] getClassPath(IJavaProject[] javaProjects) {
	HashSet<IPath> res= new HashSet<IPath>();

	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	for (int j= 0; j < javaProjects.length; j++) {
		IJavaProject curr= javaProjects[j];
		try {
			IPath outputLocation= null;

			// Not really clear yet what to do here for EFS. See bug
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=113233.

			// However if the output location is not local it is currently
			// not part of JavaRuntime.computeDefaultRuntimeClassPath either
			// so it will be simply not added to the result which would be
			// correct.
			IResource outputPathFolder= root.findMember(curr.getOutputLocation());
			if (outputPathFolder != null)
				outputLocation= outputPathFolder.getLocation();

			String[] classPath= JavaRuntime.computeDefaultRuntimeClassPath(curr);
			for (int i= 0; i < classPath.length; i++) {
				IPath path= Path.fromOSString(classPath[i]);
				if (!path.equals(outputLocation)) {
					res.add(path);
				}
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
	return res.toArray(new IPath[res.size()]);
}
 
Example 6
Source File: Platform.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
Platform(IJavaProject platformJavaProject) throws CoreException {
	this.platformJavaProject = platformJavaProject;
	this.classPath = JavaRuntime.computeDefaultRuntimeClassPath(platformJavaProject);
}