以编程方式在Eclipse中导入库 [英] Importing libraries in Eclipse programmatically
本文介绍了以编程方式在Eclipse中导入库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IPath path = new Path(C:\\ \\\myfolder\\mylibrary.jar);
libraries.add(JavaCore.newLibraryEntry(path,null,null));
//将libs添加到项目类路径
try {
javaProject.setRawClasspath(libraries.toArray(new IClasspathEntry [libraries.size()]),null);
} catch(JavaModelException e1){
e1.printStackTrace();
}
然而,我想将jtwitter文件以编程方式复制到项目文件夹我可以将其引用为jtwitter.jar。可以这样做吗?
非常感谢,
Krt_Malta
解决方案
这样做了。我想要的是将库导入到项目中,然后从项目引用它,而不是使用对外部文件的引用。
InputStream is = new BufferedInputStream(new FileInputStream(C:\\\myfolder\\mylibrary.jar) );
IFile file = project.getFile(mylibrary.jar);
file.create(is,false,null);
IPath path = file.getFullPath();
libraries.add(JavaCore.newLibraryEntry(path,null,null));
//将libs添加到项目类路径
try {
javaProject.setRawClasspath(libraries.toArray(new IClasspathEntry [libraries.size()]),null);
} catch(JavaModelException e1){
e1.printStackTrace();
}
Is there a way I could put a library (Jar file) into an Eclipse project programatically? Up to now I've managed to do an external reference to it programatically using
IPath path = new Path("C:\\myfolder\\mylibrary.jar");
libraries.add(JavaCore.newLibraryEntry(path, null, null));
//add libs to project class path
try {
javaProject.setRawClasspath(libraries.toArray(new IClasspathEntry[libraries.size()]), null);
} catch (JavaModelException e1) {
e1.printStackTrace();
}
However I'd like to copy the jtwitter file to the project folder programatically so I could reference it as jtwitter.jar only. Can this be done please?
Thanks a lot and regards, Krt_Malta
解决方案
This did the trick. What I wanted exactly is importing the library into the project and then referencing it from the project not using a reference to an external file.
InputStream is = new BufferedInputStream(new FileInputStream("C:\\myfolder\\mylibrary.jar"));
IFile file = project.getFile("mylibrary.jar");
file.create(is, false, null);
IPath path = file.getFullPath();
libraries.add(JavaCore.newLibraryEntry(path, null, null));
//add libs to project class path
try {
javaProject.setRawClasspath(libraries.toArray(new IClasspathEntry[libraries.size()]), null);
} catch (JavaModelException e1) {
e1.printStackTrace();
}
这篇关于以编程方式在Eclipse中导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文