本文整理汇总了Java中org.eclipse.jdt.launching.JavaRuntime.getLibraryLocations方法的典型用法代码示例。如果您正苦于以下问题:Java JavaRuntime.getLibraryLocations方法的具体用法?Java JavaRuntime.getLibraryLocations怎么用?Java JavaRuntime.getLibraryLocations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.launching.JavaRuntime
的用法示例。
在下文中一共展示了JavaRuntime.getLibraryLocations方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addClassPathEntries
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
public void addClassPathEntries() {
try {
final ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
final IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
LibraryLocation[] _libraryLocations = JavaRuntime.getLibraryLocations(vmInstall);
final Consumer<LibraryLocation> _function = new Consumer<LibraryLocation>() {
@Override
public void accept(final LibraryLocation eachLocation) {
IPath _systemLibraryPath = eachLocation.getSystemLibraryPath();
IClasspathEntry _newLibraryEntry = JavaCore.newLibraryEntry(_systemLibraryPath, null, null);
entries.add(_newLibraryEntry);
}
};
((List<LibraryLocation>)Conversions.doWrapArray(_libraryLocations)).forEach(_function);
int _size = entries.size();
IClasspathEntry[] _newArrayOfSize = new IClasspathEntry[_size];
IClasspathEntry[] _array = entries.<IClasspathEntry>toArray(_newArrayOfSize);
this.javaProject.setRawClasspath(_array, null);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例2: createProject
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
/**
* This method creates a new java project based on the user inputs, captured in WizardInput object.
* The new project is created in the current workspace.
* @param wizardInput
* @return IJavaProject
* @throws CoreException
* @throws IOException
**/
public IJavaProject createProject(WizardInput wizardInput) throws CoreException, IOException
{
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(wizardInput.getProjectName());
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);
IFolder binFolder = project.getFolder("bin");
binFolder.create(false, true, null);
javaProject.setOutputLocation(binFolder.getFullPath(), null);
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
for (LibraryLocation element : locations) {
entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
}
InputStream is = new BufferedInputStream(new FileInputStream(wizardInput.getSootPath().toOSString()));
IFile jarFile = project.getFile("soot-trunk.jar");
jarFile.create(is, false, null);
IPath path = jarFile.getFullPath();
entries.add(JavaCore.newLibraryEntry(path, null, null));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
IFolder sourceFolder = project.getFolder("src");
sourceFolder.create(false, true, null);
IPackageFragmentRoot root1 = javaProject.getPackageFragmentRoot(sourceFolder);
IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
newEntries[oldEntries.length] = JavaCore.newSourceEntry(root1.getPath());
javaProject.setRawClasspath(newEntries, null);
String filepath = sourceFolder.getLocation().toOSString();
File file = new File(filepath);
wizardInput.setFile(file);
try {
CodeGenerator.generateSource(wizardInput);
} catch (JClassAlreadyExistsException e) {
e.printStackTrace();
}
sourceFolder.refreshLocal(1, null);
javaProject.open(null);
return javaProject;
}
示例3: isRuntimeJar
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
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;
}
示例4: getRuntimeJar
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
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;
}
示例5: addJavaLibrariesTo
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
private void addJavaLibrariesTo(IJavaProject javaProject) throws JavaModelException {
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
for (LibraryLocation element : locations) {
entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
}
entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
}
示例6: run
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
try {
IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject("MyProject");
project.create(progressMonitor);
project.open(progressMonitor);
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = JavaCore.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, progressMonitor);
IJavaProject javaProject = JavaCore.create(project);
IFolder sourceFolder = project.getFolder("src");
sourceFolder.create(false, true, null);
Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>();
entries.addAll(Arrays.asList(javaProject.getRawClasspath()));
IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall();
LibraryLocation[] locations= JavaRuntime.getLibraryLocations(vmInstall);
for (LibraryLocation element : locations) {
entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
}
IPackageFragmentRoot fragmentRoot = javaProject.getPackageFragmentRoot(sourceFolder);
entries.add(JavaCore.newSourceEntry(fragmentRoot.getPath()));
entries.remove(JavaCore.newSourceEntry(javaProject.getPath()));
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), progressMonitor);
IPackageFragment pack = javaProject.getPackageFragmentRoot(sourceFolder).createPackageFragment("", false, null);
StringBuffer buffer = new StringBuffer();
buffer.append("public class TestImpl implements Test {\n");
buffer.append(" public boolean doTest(int i) {\n");
buffer.append(" //To implement\n");
buffer.append(" return false;\n");
buffer.append(" }\n");
buffer.append("}\n");
pack.createCompilationUnit("TestImpl.java", buffer.toString(), false, null);
buffer = new StringBuffer();
buffer.append("public interface Test {\n");
buffer.append(" public boolean doTest(int i);\n");
buffer.append("}\n");
pack.createCompilationUnit("Test.java", buffer.toString(), false, null);
}
catch(CoreException e) {
Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, Status.OK, "CoreException while creating project", e));
}
}
示例7: addClassPathEntries
import org.eclipse.jdt.launching.JavaRuntime; //导入方法依赖的package包/类
private void addClassPathEntries() {
List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
for(LibraryLocation eachLocation : JavaRuntime.getLibraryLocations(vmInstall)) {
entries.add(JavaCore.newLibraryEntry(eachLocation.getSystemLibraryPath(), null, null));
}
try {
this.javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}