Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Problem resolving @PostConstruct and @PreDestroy
Problem resolving @PostConstruct and @PreDestroy [message #1785139] Mon, 09 April 2018 23:13 Go to next message
Marcelo Ruiz is currently offline Marcelo RuizFriend
Messages: 73
Registered: April 2017
Member
Hi,

I am struggling with Eclipse not being able to resolve @PostConstruct and @PreDestroy when using Java 9. Is anyone having the same problem?

I went as far as to create a p2 repository with package-drone using
javax.annotation:javax.annotation-api:1.3.2
and added the package dependency in that project to javax.annotation version 1.3.2 but I still get the error.
If I type the import statement, the code completion suggests both annotations but still cannot be resolved.

Maven compiles the code with no problem, but eclipse cannot resolve the annotations. The weirdest thing (for me) is that classes in the same package (javax.annotation) like @Nonnull are resolved without problems.

package org.example.com.ui.e4

import javax.annotation.Nonnull;  // generated by quick fix
import javax.annotation.PostConstruct; // not generated by quick fix, but code completion shows 'PostConstruct' as option after typing 'import javax.annotation.P' but the type cannot be resolved
import javax.annotation.PreDestroy; // same as above with PostConstruct

import org.eclipse.fx.core.di.LocalInstance;

import javafx.fxml.FXMLLoader;
import javafx.scene.layout.BorderPane;

public class MyE4UIComponent {
    
    @PostConstruct
    void init(final BorderPane parent, @LocalInstance final FXMLLoader loader) {
	// add stuff to parent here
    }

    @Nonnull //no problem here, it resolves the annotation and generates the import statement 
    String getNothing() {
	return "nothing";
    }
    
    @PreDestroy // cannot resolve here
    void doNothing() {
    }
}


Does anyone know how to solve this?

Thanks!
Re: Problem resolving @PostConstruct and @PreDestroy [message #1785141 is a reply to message #1785139] Mon, 09 April 2018 23:33 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6414
Registered: July 2009
Senior Member
I think the problem is that the Module with javax.annotation is not exported anymore, and even worse in java 11 it is completely removed! I guess we need to go back an explicitly require it using import package AND ship a repackaged version
Re: Problem resolving @PostConstruct and @PreDestroy [message #1785143 is a reply to message #1785141] Tue, 10 April 2018 03:06 Go to previous messageGo to next message
Marcelo Ruiz is currently offline Marcelo RuizFriend
Messages: 73
Registered: April 2017
Member
Hi Tom,
Thanks for the reply. I saw many forum posts where people are hitting the wall regarding this very point...
Regarding your proposed solution: aren't there license restrictions to ship a repackaged version?
Re: Problem resolving @PostConstruct and @PreDestroy [message #1785144 is a reply to message #1785143] Tue, 10 April 2018 03:08 Go to previous messageGo to next message
Marcelo Ruiz is currently offline Marcelo RuizFriend
Messages: 73
Registered: April 2017
Member
I forgot to mention that with the new release cadence, it seems Oracle will surprise us much more often... as soon as a problem is dealt with, you can pretty much expect a new one in a few months...
Re: Problem resolving @PostConstruct and @PreDestroy [message #1785154 is a reply to message #1785144] Tue, 10 April 2018 06:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6414
Registered: July 2009
Senior Member
No there aren't any and ironically we just switched the codebase from the repackaged version to the one from the jre because it has caused so much pain! Now we are back in pain mode and to support java-11 we need to put java-8 users back in to dark old days where the need have 2 javax.annotation classes in their env.

What an absolute total mess!
Re: Problem resolving @PostConstruct and @PreDestroy [message #1785206 is a reply to message #1785154] Tue, 10 April 2018 22:57 Go to previous message
Marcelo Ruiz is currently offline Marcelo RuizFriend
Messages: 73
Registered: April 2017
Member
For anyone having this problem, following Tom's guidance, I solved the problem doing the following:


  1. I downloaded the javax.annotation version 1.2.0
  2. Created a plugin project with existing Jar files
  3. Verified in the manifest all the packages exported (Exported Packages in Runtime Tab)
  4. Build this new wrapper project
  5. Created a new repository in Package-Drone for javax.annotation version 1.2.0
  6. Upload the built jar file to Package-Drone
  7. Configured the Channel as P2 repository (follow Package Drone guide)
  8. Edited the Runtime Target and added the new P2 repository
  9. Reloaded the Runtime Target
  10. Cleaned all the projects
  11. On the compile error for the annotations I selected find libraries and double clicked on the displayed new library


After that, Eclispe can finally compile the RCP Project.
I nope this helps anyone having the same problem!

Edit: Altough I can compile and run the project with Eclipse, Maven is unable to find the Annotations... So this is actually not a solution

[Updated on: Mon, 16 April 2018 23:23]

Report message to a moderator

Previous Topic:java8_OSGI: NoClassDefFoundError: javafx/collections/MapChangeListener
Next Topic:How to Generate Template to create Custom E(fx)clipse Project?
Goto Forum:
  


Current Time: Tue Oct 16 04:27:54 GMT 2018

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

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

Back to the top