문제

The Netbeans Platform recently introduced annotations-based generation of resource files such as bundles and the layer.xml file.

Having a Maven-based Netbeans Platform project in Netbeans (where those annotations work) makes it easy to import the very same project into Eclipse.

But for some reason, even though the project is correctly imported (or at least it seems to be correctly imported <-- necessary libraries are downloaded, etc.), the annotations mentioned above are not executed by Eclipse.

The symptons are missing generated classes imported in classes that use those annotations.

Example:

import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
    dtd = "-//org.something.ui//Exp//EN",
autostore = false)
@TopComponent.Description(
    preferredID = "ExpTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "output", openAtStartup = true)
@ActionID(category = "Window", id = "ExpTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
    displayName = "#CTL_ExpAction",
preferredID = "ExpTopComponent")
@Messages({
  "CTL_ExpAction=Example",
  "CTL_ExpTopComponent=Example Window",
  "HINT_ExpTopComponent=This is a Example window"
})
public final class ExpTopComponent extends TopComponent {

  public ExpTopComponent() {
    initComponents();
    setName(Bundle.CTL_ExpTopComponent());
    setToolTipText(Bundle.HINT_ExpTopComponent());
    putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);

  }

  private void initComponents() {
    setLayout(new java.awt.BorderLayout());

    outlineView1 = new org.openide.explorer.view.OutlineView();
    add(outlineView1, java.awt.BorderLayout.CENTER);
  }

  private org.openide.explorer.view.OutlineView outlineView1;
  @Override
  public void componentOpened() {
    // TODO add custom code on component opening
  }

  @Override
  public void componentClosed() {
    // TODO add custom code on component closing
  }

  void writeProperties(java.util.Properties p) {
    p.setProperty("version", "1.0");
    // TODO store your settings
  }

  void readProperties(java.util.Properties p) {
    String version = p.getProperty("version");
    // TODO read your settings according to their version
  }
}

As seen in the example above, annotations are used extensivly but are not processed by Eclipse which results in the following lines not compilable because of Bundle (which should be automatically generated) not being recognized as known class.

    setName(Bundle.CTL_ExpTopComponent());
    setToolTipText(Bundle.HINT_ExpTopComponent());

Further information:

Used Eclipse is Juno and in the projects properties annotation processing is enabled.

Does anybody have any idea on how to make this work in Eclipse?

도움이 되었습니까?

해결책

Turns out, you also have to specify the libraries that contain the annotation processors for the netbeans annotations, which is tedious to say the least (annotation processing in eclipse seems counter intuitive anyway).

What works best is to run a simple maven build on the project whenever the annotation were changed and you are good to go.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top