简体   繁体   中英

Eclipse: javax.annotation PostConstruct is not called

I am using Fedora 29 and have attempted to try out a simple plugin example by creating a new Plugin Project and used the "View contribution using 4.X API" template.

I have provided the system property of:

-Dorg.eclipse.e4.core.di.debug=true

In my VM arguments under eclipse.

After enabling that debug I get the following message:

!MESSAGE Possbible annotation mismatch: method "public void hello.parts.SampleView.createPartControl(org.eclipse.swt.widgets.Composite)" annotated with "javax.annotation-api:1.2.0:javax.annotation.PostConstruct" but was looking for "javax.annotation.PostConstruct [via bootstrap classloader]"

What does this error message mean and how can I resolve it?

Here is snippet of the example of the eclipse plugin containing the PostConstruct annotation.

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

public class SampleView {
    private Label myLabelInView;

    @PostConstruct
    public void createPartControl(Composite parent) {
        System.out.println("Enter in SampleE4View postConstruct");

        myLabelInView = new Label(parent, SWT.BORDER);
        myLabelInView.setText("This is a sample E4 view");

    }

Edit:

Manifest.mf file:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Hello
Bundle-SymbolicName: hello;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: javax.inject,
 org.eclipse.osgi,
 org.eclipse.jface,
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.e4.ui.di,
 org.eclipse.e4.ui.services,
 org.eclipse.e4.core.di.annotations
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: hello
Import-Package: javax.annotation

Edit 2:

After examining the jars for javax.annotation (it is called javax.annotation-api instead of javax.annotation...) I found that they have a symbolic link to a glassfish implementation:

/usr/lib/eclipse/plugins/javax.annotation-api_1.2.0.jar -> /usr/share/java/glassfish-annotation-api.jar
/usr/lib/eclipse/plugins/javax.el-api_3.0.0.jar -> /usr/share/java/glassfish-el-api.jar
/usr/lib/eclipse/plugins/javax.inject_1.0.0.v20091030.jar -> /usr/share/java/atinject.jar
/usr/lib/eclipse/plugins/javax.servlet-api_3.1.0.jar -> /usr/share/java/glassfish-servlet-api.jar
/usr/lib/eclipse/plugins/javax.servlet.jsp_2.3.2.b01.jar -> /usr/share/java/glassfish-jsp-api/javax.servlet.jsp-api.jar

It looks like the wrong plug-in is being picked by Import-Package . There should also be a javax.annotation plugin which is the correct one. Try adding javax.annotation to the Require-Bundle list to force that to be used:

Require-Bundle: javax.inject,
 javax.annotation,
 org.eclipse.osgi,
 org.eclipse.jface,
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.e4.ui.di,
 org.eclipse.e4.ui.services,
 org.eclipse.e4.core.di.annotations

在春天你需要在应用程序上下文中添加这一行,我希望能帮助你

<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM