Eclipse4 and @PostConstruct and @PreDestroy not called (javax.annotation)

We are getting some error reports that @PostConstruct and @PreDestroy methods in Eclipse 4 RCP applications are not called by the framework.

If you are building Eclipse 4 RCP applications you shoudl enter the javax.annotation package as package dependency instead of plug-in dependency, otherwise you plug-in will be using a different @PostConstruct than the framework and your methods may not be called.

Wim Jongman fixed already the e4 tools in Bug 394327 , so a new version of the tools will also generate a package dependency.

If you are wondering where you can find the latest version of the tools, just build the e4 tools locally. 🙂

[EDIT – UPDATED entry to describe that import package is always required]

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse. Bookmark the permalink.

5 Responses to Eclipse4 and @PostConstruct and @PreDestroy not called (javax.annotation)

  1. Ferry says:

    javax.annotation normally is _not_ available by default in OSGi runtimes. You always have to import it explicitly

  2. Tom Schindl says:

    @Ferry: Unfortunately this is not true for equinox which by default provides all packages from the EE and PDE does the same

  3. Aaron Digulla says:

    It would be great when the build tools would check for things like that because they are easy to find for a computer but hard for a human.

  4. Stefan says:

    Thanks. Saved me a lot of time…

  5. Fritz says:

    Thanks! Helped me to solve my problem.

    When running my product from within Eclipse everything worked fine, but running it when built using Maven Tycho views didn’t show up. Now everything works fine 🙂

Comments are closed.