[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: How to add rt.jar to Java Build path

I should have added the complete code for non-java ui case:

IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall();
if (vmInstall != null) {
    LibraryLocation loc=
vmInstall.getVMInstallType().getDefaultLibraryLocation(
        vmInstall.getInstallLocation());
    if (loc != null) {
        return new IPath[] {
            new Path(loc.getSystemLibrary().getPath()),
            new Path(loc.getSystemLibrarySource().getPath()),
            loc.getPackageRootPath()
        };
    }
}

"Martin Aeschlimann" <Martin_Aeschlimann@xxxxxxx> wrote in message
news:9kbf5h$bpp$1@xxxxxxxxxxxxxxxx
> The only special thing the Java wizard does for you is adding the JRE
> library to the classpath.
>
> JavaUI introduces the concept of a pluggable JRE (switching JRE without
> changing each project's class path), and therefore defines the classpath
> variables 'JRE_LIB', 'JRE_SRC' and 'JRE_SRCROOT'. As the Java UI contains
> the UI for configuring the JREs, these variables are defined and
maintained
> by the Java UI plugin: A plugin that uses these variables must have a
> dependency on Java UI, and before usage, the Java UI plugin must be
loaded.
> A problem of the current implementation is that the variable name
constants
> are not in the public API.
>
> If you depend on the Java UI plugin, and want to use the pluggable JRE,
you
> would programmatically create a Java project like this:
>
> - create and open a IProject
> - set the nature (JavaCore.NATURE_ID)
> - get the IJavaProject handle:
>     IJavaProject jproject= JavaCore.create(project);
> - set the classpath, for example
>     jproject.setRawClasspath(new IClasspathEntry[] {
>         JavaCore.newSourceEntry(project.getFullPath()),
>         JavaCore.newVariableEntry("JRE_LIB", "JRE_SRC", "JRE_SRCROOT");
>     }, progressMonitor);
> - set the build output location
>     jproject.setOutputLocation(project.getFullPath(), progressMonitor);
>
> If you dont want to depend on the Java UI plugin and simply need a
location
> of a JRE, you can use the jdt.launching plugin and get the location like
> using:
>     org.eclipse.jdt.launching.JavaRuntime.getDefaultVMInstall()
> (.getInstallLocation())
>
> The default location is derived from the JRE location used to run eclipse,
> and might not find a installation.
>
> When setting the classpath, instead of creating the variable entry, set a
> library entry
> LibraryLocation loc;
>     jproject.setRawClasspath(new IClasspathEntry[] {
>         JavaCore.newSourceEntry(project.getFullPath()),
>         JavaCore.newVariableEntry(
>             new Path(loc.getSystemLibrary().getPath()),
>             new Path(loc.getSystemLibrarySource().getPath()),
>             loc.getPackageRootPath())
>     }, progressMonitor);
>
> Martin
>
> "Jeff McAffer" <jeff_mcaffer@xxxxxxx> wrote in message
> news:9jp1am$ndo$1@xxxxxxxxxxxxxxxx
> > This does not really help someone who is trying to create a Java project
> > programmatically.  The problem here is that (as far as I have seen) Java
> > projects *must* be created using the wizard since the wizard's does
> special
> > work after creating the project with a Java nature.  Unless that work
uses
> > only API and people want to copy it, making a Java project is hard.
> >
> > At the very least there should be API for creating a Java project.  This
> is
> > somewhat less than optimal as you may have someone who wants to create a
> > project that has the Java, PDE, Foo and Bar natures.  Even if they all
> > supplied "create" API, you can only create the project once so you have
to
> > choose one.
> >
> > This is a general issue for nature-writers to consider.  You should
assume
> > that your nature can be added/removed from a project by people other
than
> > you.
> >
> > Jeff
> >
> > "Martin Aeschlimann" <aeschli@xxxxxxx> wrote in message
> > news:9jmctc$ttc$1@xxxxxxxxxxxxxxxx
> > > The NewJavaProjectWizardPage creates and configures the JavaProject
for
> > you.
> > > The idea is that you add the NewJavaProjectWizardPage to your wizard.
> > > Does this help?
> > >
> > > Martin
> > >
> > > "Terry Chan" <terrych@xxxxxxxxxx> wrote in message
> > > news:9jhou2$h3g$1@xxxxxxxxxxxxxxxx
> > > > Hello,
> > > > I have a plugin that programmatically creates a project, and
> associates
> > it
> > > > with the java nature.  However, the java project does not have a
Java
> > > > Build Path.  How do I programmatically add the default JRE_LIB
rt.jar
> to
> > > > the project's Java Build path?
> > > > Thank you.
> > > > Terry
>
>
>