gpt4 book ai didi

eclipse - 以编程方式在插件中设置java eclipse项目的JRE

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:54:37 25 4
gpt4 key购买 nike

我正在尝试以编程方式为我的插件创建 eclipse 项目。我使用这段代码来创建项目:

IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject project = workspaceRoot.getProject(projectName);
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));
}

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

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

IPackageFragmentRoot packageRoot = 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(packageRoot.getPath());
javaProject.setRawClasspath(newEntries, null);

但由于它在 eclipse 应用程序中运行,因此未设置 JRE 系统库。

那么如何以编程方式将 JRE 添加到 eclipse 应用程序中的项目中呢?

最佳答案

entries.add(JavaRuntime.getDefaultJREContainerEntry());

关于eclipse - 以编程方式在插件中设置java eclipse项目的JRE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6982981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com