Java build path problem [message #259241] |
Thu, 26 March 2009 06:10  |
Eclipse User |
|
|
|
HI,
I am working on a simple plug-in where I need to add list of the jar
files to the java build path. Following is the snapshot of a code adding
jars to build path.
File dir = new File("dirlocation");
// This filter only returns jars
FileFilter fileFilter = new FileFilter() {
public boolean accept(File file) {
return file.getName().contains(".jar");
}
};
File[] files = dir.listFiles(fileFilter)
if(files!=null){
IClasspathEntry[] entry = new IClasspathEntry[files.length];
for (int i=0; i<files.length; i++) {
// Get filename of file or directory
File file = files[i];
String absolutepath =file.getAbsolutePath();
entry[i] = JavaCore.newLibraryEntry(new
Path(absolutepath),null,null,false);
}
try {
IProgressMonitor monitor = new NullProgressMonitor();
//adding to the build path
javaproject.setRawClasspath(entry, monitor);
} catch (JavaModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When I execute above code the jar are getting added to the java build
path. Now the real problem is, code is removing JRE library which is added
default when you create a java nature project. Is there any thinking
wrong in my code .When I use below function to add the JRE to the build
path its giving warning like JRE_LIB is deprecated: Use the JRE System
Library instead.
JavaRuntime.getJREVariableEntry()
How to add the JRE system library or workspace default JRE to the java
build path?
Thanks in advance
Bhanu Prakash.
|
|
|
|
Re: Java build path problem [message #259248 is a reply to message #259245] |
Thu, 26 March 2009 15:55  |
Eclipse User |
|
|
|
"Prakash G.R." <grprakash@gmail.com> wrote in message
news:gqfndr$iqd$1@build.eclipse.org...
>> //adding to the build path javaproject.setRawClasspath(entry, monitor);
>
> You are not adding to the classpath, you are simply setting the
> classpath. Ideally, you should get the existing classpath enties, append
> your classpath entry and then set that entries on the project.
And be aware that there is no threadsafe way to do this, i.e., if two
threads are modifying the classpath at the same time there is a data race.
You may need to do the classpath modification on the UI thread to avoid
this.
|
|
|
Powered by
FUDForum. Page generated in 0.03681 seconds