Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Oomph » Configuring tools.jar as JRE Library of Java 8 JRE ?
Configuring tools.jar as JRE Library of Java 8 JRE ? [message #1857142] Thu, 19 January 2023 16:33 Go to next message
NoDataFound - is currently offline NoDataFound -Friend
Messages: 10
Registered: October 2017
Junior Member
Hello,

I would like to know / understand if this is possible to configure a Java JRE to have the (unfamous) tools.jar as JRE library in a installation setup:

    <setupTask
        xsi:type="jdt:JRETask"
        version="JavaSE-1.8"
        location="${jre.location-1.8}">
      <jreLibrary
          libraryPath="../lib/tools.jar"
          externalAnnotationsPath="../lib/tools.jar"/>
    </setupTask>


The task is not adding the tools.jar and I don't know what's wrong here (JDK is added, and I get an error if I don't have externalAnnotationsPath).
Re: Configuring tools.jar as JRE Library of Java 8 JRE ? [message #1857154 is a reply to message #1857142] Fri, 20 January 2023 08:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I'll need to investigate, time permitting. Or you can set up an Oomph environment:

https://www.eclipse.org/setups/installer/?url=http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/configurations/OomphConfiguration.setup&show=true

Start the Runtime Workspace, use Navigate -> Open Setup -> Workspace, copy your JRE task in there, run Help -> Perform Setup Tasks, and then debug what happens in JRETaskImpl.perform to help fix any problem either in the code or in what you have specified in the task.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Configuring tools.jar as JRE Library of Java 8 JRE ? [message #1857157 is a reply to message #1857154] Fri, 20 January 2023 09:44 Go to previous messageGo to next message
NoDataFound - is currently offline NoDataFound -Friend
Messages: 10
Registered: October 2017
Junior Member
In debug, yes, I can see the library being processed ... but my understanding of the task :

IPath installPath = new Path(installLocation.getCanonicalPath());
            for (JRELibrary jreLibrary : jreLibraries)
            {
              String libraryPath = jreLibrary.getLibraryPath();
              String externalAnnotationsPathLiteral = jreLibrary.getExternalAnnotationsPath();
              if (libraryPath != null && externalAnnotationsPathLiteral != null)
              {
                IPath jreLibraryPath = installPath.append(libraryPath);
                LibraryLocation[] libraryLocations = vmStandin.getLibraryLocations();
                for (int i = 0; i < libraryLocations.length; i++)
                {
                  LibraryLocation libraryLocation = libraryLocations[i];
                  IPath systemLibraryPath = libraryLocation.getSystemLibraryPath();
                  if (jreLibraryPath.equals(systemLibraryPath))
                  {
                    Path externalAnnotationsPath = new Path(externalAnnotationsPathLiteral);
                    try
                    {
                      if (!externalAnnotationsPath.equals(libraryLocation.getExternalAnnotationsPath()))
                      {
                        LibraryLocation newLibraryLocation = new LibraryLocation(systemLibraryPath, libraryLocation.getSystemLibrarySourcePath(),
                            libraryLocation.getPackageRootPath(), libraryLocation.getJavadocLocation(), libraryLocation.getIndexLocation(),
                            externalAnnotationsPath);
                        libraryLocations[i] = newLibraryLocation; // <-- update existing
                      }
                    }
                    catch (NoSuchMethodError ex)
                    {
                      //$FALL-THROUGH$
                    }
                    break;
                  }
                }
              }
            }


Is that me or this code is only adding the "external annotation" to the existing library and completely ignoring new JRE libraries ?

I also see in debug that I should use lib/tools.jar because the install path if the JDK home, rather than the JRE home.

I tried to fix that:

          if (!jreLibraries.isEmpty())
          {
            if (vmStandin.getLibraryLocations() == null)
            {
              // We have to set this to an empty array first in order for the real setLibraryLocations() call to have any effect.
              vmStandin.setLibraryLocations(new LibraryLocation[0]);
              vmStandin.setLibraryLocations(type.getDefaultLibraryLocations(installLocation));
            }

            IPath installPath = new Path(installLocation.getCanonicalPath());
            LibraryLocation[] libraryLocations = vmStandin.getLibraryLocations();
            List<LibraryLocation> newLibraryLocations = new ArrayList<>(asList(libraryLocations));
            for (JRELibrary jreLibrary : jreLibraries)
            {
              String libraryPath = jreLibrary.getLibraryPath();
              String externalAnnotationsPathLiteral = jreLibrary.getExternalAnnotationsPath();
              if (libraryPath != null)
              {
                IPath jreLibraryPath = installPath.append(libraryPath);
                boolean found = false; 
                if (externalAnnotationsPathLiteral != null)
                {
                  for (int i = 0; i < libraryLocations.length; i++)
                  {
                    LibraryLocation libraryLocation = libraryLocations[i];
                    IPath systemLibraryPath = libraryLocation.getSystemLibraryPath();
                    if (jreLibraryPath.equals(systemLibraryPath))
                    {
                      Path externalAnnotationsPath = new Path(externalAnnotationsPathLiteral);
                      try
                      {
                        if (!externalAnnotationsPath.equals(libraryLocation.getExternalAnnotationsPath()))
                        {
                          LibraryLocation newLibraryLocation = new LibraryLocation(systemLibraryPath, libraryLocation.getSystemLibrarySourcePath(),
                              libraryLocation.getPackageRootPath(), libraryLocation.getJavadocLocation(), libraryLocation.getIndexLocation(),
                              externalAnnotationsPath);
                          libraryLocations[i] = newLibraryLocation;
                          found = true;
                        }
                      }
                      catch (NoSuchMethodError ex)
                      {
                        //$FALL-THROUGH$
                      }
                      break;
                    }
                  }
                }
                if (!found)
                {
                  // (IPath libraryPath, IPath sourcePath, IPath packageRoot, URL javadocLocation, URL indexLocation, IPath externalAnnotations)
                  IPath sourcePath = Path.EMPTY;
                  IPath packageRoot = Path.EMPTY;
                  URL javadocLocation = null;
                  URL indexLocation = null;
                  IPath externalAnnotationsPath = externalAnnotationsPathLiteral == null ? null : new Path(externalAnnotationsPathLiteral);
                  newLibraryLocations
                      .add(new LibraryLocation(jreLibraryPath, sourcePath, packageRoot, javadocLocation, indexLocation, externalAnnotationsPath));
                }
              }

            }
            vmStandin.setLibraryLocations(newLibraryLocations.toArray(LibraryLocation[]::new));
          }


This effectively add the new tools.jar in the libraries, there is a red cross in the Installed JREs system libraries for the one I added.

It seems it is related to the "external annotation" => the setup should ignore it, but I kind of remember that I was forced to set an externalAnnotationsPath attribute.

Re: Configuring tools.jar as JRE Library of Java 8 JRE ? [message #1857177 is a reply to message #1857157] Sat, 21 January 2023 12:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
It looks to me like this code (which was contributed, not written by me) was only designed to add annotations to and existing library path entry.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=526214

I suppose it could be extended to allow adding additional jars...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Problem with installing.
Next Topic:Maven Location
Goto Forum:
  


Current Time: Fri Mar 29 11:59:03 GMT 2024

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

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

Back to the top