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

The following examples show how to use org.eclipse.jdt.launching.JavaRuntime#getLibraryLocations() . 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: RuntimeUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
public static boolean isRuntimeJar(File jar) throws IOException {
	IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
	LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
	for (LibraryLocation library : locations) {
		File runtime = JavaCore.newLibraryEntry(library.getSystemLibraryPath(), null, null).getPath().toFile().getCanonicalFile();
		if(runtime.equals(jar.getCanonicalFile())){
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: RuntimeUtils.java    From JReFrameworker with MIT License 5 votes vote down vote up
public static File getRuntimeJar(String jarName) throws IOException {
	IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
	LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
	for (LibraryLocation library : locations) {
		File runtime = JavaCore.newLibraryEntry(library.getSystemLibraryPath(), null, null).getPath().toFile().getCanonicalFile();
		if(runtime.getName().equals(jarName)){
			return runtime;
		}
	}
	return null;
}
 
Example 3
Source File: TestUtils.java    From CogniCrypt with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * This method creates a empty JavaProject in the current workspace
 * 
 * @param projectName for the JavaProject
 * @return new created JavaProject
 * @throws CoreException
 */
public static IJavaProject createJavaProject(final String projectName) throws CoreException {

	final IWorkspaceRoot workSpaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	deleteProject(workSpaceRoot.getProject(projectName));

	final IProject project = workSpaceRoot.getProject(projectName);
	project.create(null);
	project.open(null);

	final IProjectDescription description = project.getDescription();
	description.setNatureIds(new String[] {JavaCore.NATURE_ID});
	project.setDescription(description, null);

	final IJavaProject javaProject = JavaCore.create(project);

	final IFolder binFolder = project.getFolder("bin");
	binFolder.create(false, true, null);
	javaProject.setOutputLocation(binFolder.getFullPath(), null);

	final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
	final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
	final LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
	for (final LibraryLocation element : locations) {
		entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
	}
	// add libs to project class path
	javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);

	final IFolder sourceFolder = project.getFolder("src");
	sourceFolder.create(false, true, null);

	final IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(sourceFolder);
	final IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
	final IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
	System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
	newEntries[oldEntries.length] = JavaCore.newSourceEntry(packageRoot.getPath());
	javaProject.setRawClasspath(newEntries, null);

	return javaProject;
}
 
Example 4
Source File: InternalImpl.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
@Override
public void createJavaProject(String projectName) throws RemoteException {

  log.trace("creating java project: " + projectName);

  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

  try {

    project.create(null);
    project.open(null);

    IProjectDescription description = project.getDescription();
    description.setNatureIds(new String[] {JavaCore.NATURE_ID});
    project.setDescription(description, null);

    IJavaProject javaProject = JavaCore.create(project);

    Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>();

    entries.add(JavaCore.newSourceEntry(javaProject.getPath().append("src"), new IPath[0]));

    IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();

    LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);

    for (LibraryLocation element : locations) {
      entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
    }

    javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);

  } catch (CoreException e) {
    log.error("unable to create java project '" + projectName + "' :" + e.getMessage(), e);
    throw new RemoteException(e.getMessage(), e.getCause());
  }
}