Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Get classpath variables programmatically
Get classpath variables programmatically [message #252055] Mon, 17 March 2008 12:42 Go to next message
Eclipse UserFriend
How do it get classpath variables programmatically? I defined a new
classpath variable MY_HOME to point to a directory and tried to use the
following code to access it in my eclipse plug-in:

IPath bootstrapPath = new Path("MY_HOME").append("jlibs.jar");
IRuntimeClasspathEntry bootstrapEntry =
JavaRuntime.newVariableRuntimeClasspathEntry(bootstrapPath);
bootstrapEntry.setClasspathProperty(IRuntimeClasspathEntry.U SER_CLASSES);

Doen't seem to work.. can anyone help me ?
Re: Get classpath variables programmatically [message #252104 is a reply to message #252055] Wed, 19 March 2008 10:30 Go to previous message
Eclipse UserFriend
Ok, I found the answer myself..

I could use JavaCore.getClasspathVariable(String variablename). But i
cannot use it in a headless plug-in.
The specific scenario I had in mind was to use the path pointed to by a
classpath variable in a launch configuration. I was trying to build a launch
configuration programmatically. For that purpose, there is a simple method
call in the JavaRuntime class which acheives this:

Here's an example:

IRuntimeClasspathEntry bootstrapEntry =
JavaRuntime.newVariableRuntimeClasspathEntry(new Path("JRE_LIB"));

And, if you look at the lauch configuration, you can add entries to the
bootstrap classpath or the user-defined classes. To add this environment
variable entry to the bootstrap classpath, you just need to say:

bootstrapEntry.setClasspathProperty(IRuntimeClasspathEntry.B OOTSTRAP_CLASSES);

OR if you need to add it to the user-defined entries, you would say:

IRuntimeClasspathEntry userEntry =
JavaRuntime.newVariableRuntimeClasspathEntry(new Path("JRE_LIB"));
userEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_C LASSES);

Or if you want to make another entry, and still add it to classpath , but
not display it in the "classpath" tab al all (kinda hiding it), you would
say:

IRuntimeClasspathEntry hiddenOrDefaultEntry =
JavaRuntime.newVariableRuntimeClasspathEntry(new Path("JRE_LIB"));
hiddenOrDefaultEntry
..setClasspathProperty(IRuntimeClasspathEntry.STANDARD_CLASS ES);

.. This would add the entry to the classpath, but the entry would not be
displayed in the launch configuration's classpath tab.

Another example: If you wanted to add an external jar file to the
user-defined classes section of the classpath, you would do that with the
following couple of lines:

IRuntimeClasspathEntry myJarEntry =JavaRuntime.
newArchiveRuntimeClasspathEntry(new Path("/usr/lib/myjarfile.jar"));
myJarEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_ CLASSES);

Hope this helps anyone who tries to build a launch config programmatically.
It aslo helps to read the article at:
http://www.eclipse.org/articles/Article-Java-launch/launchin g-java.html

"Arun Sudhir" <arunsudhir@gmail.com> wrote in message
news:frm71m$ug0$1@build.eclipse.org...
> How do it get classpath variables programmatically? I defined a new
> classpath variable MY_HOME to point to a directory and tried to use the
> following code to access it in my eclipse plug-in:
>
> IPath bootstrapPath = new Path("MY_HOME").append("jlibs.jar");
> IRuntimeClasspathEntry bootstrapEntry =
> JavaRuntime.newVariableRuntimeClasspathEntry(bootstrapPath);
> bootstrapEntry.setClasspathProperty(IRuntimeClasspathEntry.U SER_CLASSES);
> Doen't seem to work.. can anyone help me ?
Previous Topic:How to step thru generic classes using debugger ?
Next Topic:Searching from a not required project
Goto Forum:
  


Current Time: Sat Apr 26 08:45:14 EDT 2025

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

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

Back to the top