|
|
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 |
NoDataFound - 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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03772 seconds