创建向导时为其添加path,指为jar添加到path里面
@Override
protected void execute(IProgressMonitor monitor) throws CoreException,
InvocationTargetException, InterruptedException {
super.execute(monitor);
try {
// 将工程转为java工程
IJavaProject fCurrJProject = JavaCore.create(project);
// 获得Classpath
IClasspathEntry[] fEntries = fCurrJProject.getRawClasspath();
ArrayList<IClasspathEntry> newEntries = new ArrayList(
fEntries.length + 1);
for (int i = 0; i < fEntries.length; i++) {
IClasspathEntry curr = fEntries;
newEntries.add(curr);
}
// 将设置为源目录的文件夹
IPath myLib1 = fCurrJProject.getProject().getFullPath().append("libs/freemarker.jar");
IClasspathEntry myNewEntry1 = JavaCore.newLibraryEntry(myLib1, null, null, true);//这里使用的是newLibraryEntry 创建一个lib,这个会直接向.classpath写入一个lib库配置
newEntries.add(myNewEntry1);
IPath myLib2 = fCurrJProject.getProject().getFullPath().append("libs/log4j-1.2.13.jar");
IClasspathEntry myNewEntry2 = JavaCore.newLibraryEntry(myLib2, null, null, true);//这里使用的是newLibraryEntry 创建一个lib,这个会直接向.classpath写入一个lib库配置
newEntries.add(myNewEntry2);
fEntries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
// 把新的Classpath付给工程
fCurrJProject.setRawClasspath(fEntries, new SubProgressMonitor(monitor, 2));
//创建工程
create();
} finally {
monitor.done();
}
}