3
我有一個java項目,包含所有二進制文件,源文件和庫。 我已經將它放在一個eclipse工作區中,爲了某種目的,我想將它轉換成一個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項目編程方式使用二進制文件,源文件和庫,我有轉換。
我不想使用eclipse的GUI,而是以編程方式進行。 –