Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Only add JREContainerEntry when not yet set(Programmatically update JREContainerEntry when JavaProject doesnt contain one)
Only add JREContainerEntry when not yet set [message #1756440] Thu, 16 March 2017 21:36 Go to next message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Hello everyone.

I am working on a importer for Bndtools and facing the problem that I dont want to add a JRE-Container if the Java-Project which has existing settings already has one.

List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(javaProject.getRawClasspath()));
entries.add(JavaRuntime.getDefaultJREContainerEntry());
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);


Thats what I am doing now, but this way, I could easily end up with two Container within the project. For example the java-project which I create already defined a JRE-7 container, but in my environment JRE-8 is the default. Unfortunately, the ClasspathEntries provide no real information which I could use to check if this entry is a JRE-container.

So, how can I check if a Java project has a JRE-container?
Thanks

[Updated on: Thu, 16 March 2017 21:38]

Report message to a moderator

Re: Only add JREContainerEntry when not yet set [message #1756447 is a reply to message #1756440] Fri, 17 March 2017 04:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33264
Registered: July 2009
Senior Member
It seems to me that you can use org.eclipse.jdt.core.IClasspathEntry.getEntryKind() and test for org.eclipse.jdt.core.IClasspathEntry.CPE_CONTAINER. And in that case, if it's a JRE container, the path will conform to what's described in org.eclipse.jdt.launching.JavaRuntime.JRE_CONTAINER. Perhaps there's a better way...



Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Only add JREContainerEntry when not yet set [message #1756500 is a reply to message #1756447] Fri, 17 March 2017 20:49 Go to previous message
Marc Schlegel is currently offline Marc SchlegelFriend
Messages: 69
Registered: July 2009
Member
Thanks for the idea Ed.

edited:

The previous message was wrong because my workspace was already corrupted so that Classpath-entries were missing.

This is what I ended up with and seems to work for now

        boolean jreContainerAvailable = false;
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath() != null && entry.getPath().toString().startsWith(JavaRuntime.JRE_CONTAINER)) {
                jreContainerAvailable = true;
                break;
            }
        }
        if (!jreContainerAvailable) {
            entries.add(JavaRuntime.getDefaultJREContainerEntry());
            javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
        }

[Updated on: Tue, 21 March 2017 12:10]

Report message to a moderator

Previous Topic:Measuring compilation time of a Java project
Next Topic:JUnit Plug-In Test is run over and over again
Goto Forum:
  


Current Time: Sun Dec 22 06:27:25 GMT 2024

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

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

Back to the top