Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Java build path problem
Java build path problem [message #259241] Thu, 26 March 2009 06:10 Go to next message
Eclipse UserFriend
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 #259245 is a reply to message #259241] Thu, 26 March 2009 07:03 Go to previous messageGo to next message
Eclipse UserFriend
> //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.

- Prakash
--
http://blog.eclipse-tips.com
Re: Java build path problem [message #259248 is a reply to message #259245] Thu, 26 March 2009 15:55 Go to previous message
Eclipse UserFriend
"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.
Previous Topic:Diff computation or change events for AST?
Next Topic:"Run As > JUnit Test" on inherited test method
Goto Forum:
  


Current Time: Wed May 07 10:55:04 EDT 2025

Powered by FUDForum. Page generated in 0.03747 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top