Home » Language IDEs » Java Development Tools (JDT) » (setting classpath programatically for a java project)
(setting classpath programatically for a java project) [message #18320] |
Fri, 09 May 2003 13:36 |
Eclipse User |
|
|
|
Originally posted by: pradheept.hotmail.com
Need solution for this problem? (setting classpath programatically for a
java project)
I am creating plugin which will create a java project and extract some
code in that. then i have
to build that code. for that i need to set two jar filenames in classpath
which are under a location.
how to set that pls. provide snippet..
/*************************************
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 2];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[entries.length] = JavaCore.newLibraryEntry(new
Path(jdoJarName), null, null);
newEntries[entries.length + 1] = JavaCore.newLibraryEntry(new
Path(pjrtJarName), null, null);
// newEntries[entries.length] =
JavaCore.newLibraryEntry(new Path(jdoJarName), null, null);
// newEntries[entries.length + 1] =
JavaCore.newLibraryEntry(new Path(pjrtJarName), null, null);
if (!jp.hasClasspathCycle(newEntries)) {
jp.setRawClasspath(newEntries, new NullProgressMonitor());
}
*******************/ This part of code adds the jar to classpath but it is
giving errors in task list as
Kind Status Priority Description Resource In Folder Location
Error The project was not built due to classpath errors (incomplete or
involved in cycle).
Error Missing required library:
'D:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/jdo.jar'.
Error Missing required library:
'D:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/persistj-runt ime.jar'.
***************************
Note : d:\ is changed
****************************
expecting your mail,
thanx in advance
Pradheep T
|
|
|
Re: (setting classpath programatically for a java project) [message #18391 is a reply to message #18320] |
Fri, 09 May 2003 14:20 |
Eclipse User |
|
|
|
Originally posted by: oscarmartin.es.ibm.com
Hope this helps
public static final String DSEGB_JAR_PATH = "RUNTIME_JARS/dsegb.jar";
public static final String DSEBASECOMMON_JAR_PATH =
"RUNTIME_JARS/DSEBaseCommon.jar";
.....
protected static void addContainerClasspaths(IJavaProject javaProject) {
try {
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
boolean jreFound = false;
boolean dseGuiFound = false;
boolean dseBaseFound = false;
if (classpathEntries==null)
classpathEntries = new IClasspathEntry[0];
if (classpathEntries!=null) {
for (int index=0; !jreFound && index<classpathEntries.length; index++)
jreFound =
classpathEntries[index].getPath().toString().equals("JRE_LIB ");
for (int index=0; !dseGuiFound && index<classpathEntries.length; index++)
dseGuiFound =
classpathEntries[index].getPath().toString().equals(DSEGB_JA R_PATH);
for (int index=0; !dseBaseFound && index<classpathEntries.length;
index++)
dseBaseFound =
classpathEntries[index].getPath().toString().equals(DSEBASEC OMMON_JAR_PATH);
}
if (!jreFound)
classpathEntries = addClasspathEntry(classpathEntries,
JavaCore.newVariableEntry(new Path("JRE_LIB"), new Path("JRE_SRC"), new
Path("JRE_SRCROOT"), false));
if (!dseGuiFound)
classpathEntries = addClasspathEntry(classpathEntries,
JavaCore.newVariableEntry(new Path(DSEGB_JAR_PATH), null, null,true));
if (!dseBaseFound)
classpathEntries = addClasspathEntry(classpathEntries,
JavaCore.newVariableEntry(new Path(DSEBASECOMMON_JAR_PATH), null, null,
true));
URL url =
RADGeneratorsPlugin.getDefault().getDescriptor().getInstallU RL();
URL resolved = Platform.resolve(url);
JavaCore.setClasspathVariable("RUNTIME_JARS", new
Path(resolved.getPath()),null);
if (!jreFound || !dseGuiFound || !dseBaseFound)
javaProject.setRawClasspath(classpathEntries, null);
}
catch (Throwable th) {
th.printStackTrace(System.err);
}
}
protected static IClasspathEntry[] addClasspathEntry(IClasspathEntry[]
classpathEntries, IClasspathEntry classpathEntry) {
IClasspathEntry[] result = new IClasspathEntry[classpathEntries.length
+ 1];
System.arraycopy(classpathEntries, 0 , result, 0,
classpathEntries.length);
result[result.length-1] = classpathEntry;
return result;
}
|
|
|
Re: (setting classpath programatically for a java project) [message #19742 is a reply to message #18320] |
Mon, 12 May 2003 11:16 |
Philippe Mulet Messages: 229 Registered: July 2009 |
Senior Member |
|
|
The path 'D:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/jdo.jar' looks
suspicious to me.
Shouldn't it be: 'D/:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/jdo.jar' ?
(note the leading /)
"pradheep" <pradheept@hotmail.com> wrote in message
news:b9gat6$mh2$1@rogue.oti.com...
> Need solution for this problem? (setting classpath programatically for a
> java project)
>
> I am creating plugin which will create a java project and extract some
> code in that. then i have
> to build that code. for that i need to set two jar filenames in classpath
> which are under a location.
> how to set that pls. provide snippet..
> /*************************************
> IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 2];
> System.arraycopy(entries, 0, newEntries, 0, entries.length);
>
> newEntries[entries.length] = JavaCore.newLibraryEntry(new
> Path(jdoJarName), null, null);
> newEntries[entries.length + 1] = JavaCore.newLibraryEntry(new
> Path(pjrtJarName), null, null);
>
> // newEntries[entries.length] =
> JavaCore.newLibraryEntry(new Path(jdoJarName), null, null);
> // newEntries[entries.length + 1] =
> JavaCore.newLibraryEntry(new Path(pjrtJarName), null, null);
>
> if (!jp.hasClasspathCycle(newEntries)) {
> jp.setRawClasspath(newEntries, new NullProgressMonitor());
> }
> *******************/ This part of code adds the jar to classpath but it is
> giving errors in task list as
>
> Kind Status Priority Description Resource In Folder Location
> Error The project was not built due to classpath errors (incomplete or
> involved in cycle).
> Error Missing required library:
> 'D:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/jdo.jar'.
> Error Missing required library:
> 'D:eclipse/RC2/plugins/com.abc.ide.eclipse/lib/persistj-runt ime.jar'.
> ***************************
> Note : d:\ is changed
> ****************************
>
> expecting your mail,
>
> thanx in advance
>
> Pradheep T
>
|
|
|
Goto Forum:
Current Time: Wed Feb 05 17:50:51 GMT 2025
Powered by FUDForum. Page generated in 0.03633 seconds
|