Problem resolving @PostConstruct and @PreDestroy [message #1785139] |
Mon, 09 April 2018 19:13  |
Eclipse User |
|
|
|
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 #1785206 is a reply to message #1785154] |
Tue, 10 April 2018 18:57  |
Eclipse User |
|
|
|
For anyone having this problem, following Tom's guidance, I solved the problem doing the following:
- I downloaded the javax.annotation version 1.2.0
- Created a plugin project with existing Jar files
- Verified in the manifest all the packages exported (Exported Packages in Runtime Tab)
- Build this new wrapper project
- Created a new repository in Package-Drone for javax.annotation version 1.2.0
- Upload the built jar file to Package-Drone
- Configured the Channel as P2 repository (follow Package Drone guide)
- Edited the Runtime Target and added the new P2 repository
- Reloaded the Runtime Target
- Cleaned all the projects
- 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 19:23] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.08026 seconds