【发布时间】:2016-08-01 16:27:32
【问题描述】:
我有一个包含所有二进制文件、源文件和库的 java 项目。 我已将它放在 Eclipse 工作区中,出于某种目的,我想将其转换为 Eclipse 项目。 我为以下任务编写了以下代码行。
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IPath rootPath = root.getLocation();
File rootFile = rootPath.toFile();
File[] contents = rootFile.listFiles();
for(File file : contents) {
if(file.isDirectory() && !file.getName().startsWith(".")) {
File[] projectContents = file.listFiles();
//First create a simple project of type org.eclipse.core.resources.IProject:
IProject project = root.getProject(file.getName());
if(!project.exists()) {
project.create(null);
}
else {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
}
if (!project.isOpen()) {
project.open(null);
}
IFolder binFolder = project.getFolder("bin");
if(!binFolder.exists()) {
binFolder.create(false, true, null);
}
//Now we can create our Java project
IJavaProject javaProject = JavaCore.create(project);
javaProject.setOutputLocation(binFolder.getFullPath(), null);
<Remaining lines of code>
}
}
现在我想使用我已经构建的类文件。所以我评论了以下几行:
IFolder binFolder = project.getFolder("bin");
if(!binFolder.exists()) {
binFolder.create(false, true, null);
}
javaProject.setOutputLocation(binFolder.getFullPath(), null);
但即使现在 bin 文件夹已被创建并在其中生成类文件。这些类文件不是我拥有的,因为它们的属性中都有最新的时间戳。
我很确定是因为这条线。
IJavaProject javaProject = JavaCore.create(project);
谁能告诉我为什么会这样。我什至没有在下面添加这些专门用于构建项目的代码行。
if(!javaProject.hasBuildState()) {
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
}
如果您还可以告诉我如何使用我拥有的二进制文件、源文件和库以编程方式将 java 项目转换为 eclipse 项目,我将不胜感激。
【问题讨论】:
标签: java eclipse eclipse-plugin eclipse-rcp