java - 让 Netbeans 平台注释在 Eclipse 中工作

标签 java eclipse annotations netbeans-platform annotation-processing

最近推出了 Netbeans 平台 annotations-based生成资源文件,例如bundles和layer.xml文件。

在 Netbeans 中拥有一个基于 Maven 的 Netbeans 平台项目(这些注释在其中发挥作用)可以轻松地将同一项目导入到 Eclipse 中。

但由于某种原因,即使项目已正确导入(或者至少看起来已正确导入<--下载了必要的库等),上述注释也不会被 Eclipse 执行。

症状缺少在使用这些注释的类中导入的生成类。

示例:

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
  }
}

如上例所示,注释被广泛使用,但 Eclipse 不处理,这会导致以下几行无法编译,因为 Bundle(应该自动生成)不被识别为已知类。

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

更多信息:

使用的Eclipse是Juno,并且在项目属性中启用了注释处理。

有人知道如何在 Eclipse 中实现此功能吗?

最佳答案

事实证明,您还必须指定包含 netbeans 注释的注释处理器的库,这至少可以说是乏味的(无论如何,Eclipse 中的注释处理似乎违反直觉)。

最有效的方法是每当注释发生更改时就在项目上运行简单的 Maven 构建,这样就可以开始了。

关于java - 让 Netbeans 平台注释在 Eclipse 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14127553/

相关文章:

java - 无法从 MapReduce 代码访问 HBase

java - 尝试启动应用程序时出现 Eclipse "Permission denied"错误

java - %trimmedwindow.label.eclipseSDK 作为标题栏文本 : Bug 373988

java - 有人有java注释 "java.lang.Synthetic"的背景吗?

java - 尝试使用多个一维数组同时读取 Java 中的文件

java - 如何使用 AS6 在 JMX 中使用 CDI 获取 'JBoss service'?

java - 尽管添加了 android :usesCleartextTraffic and android:networkSecurityConfig,但仍不允许明文 HTTP 流量

java - sendMessage() 方法在哪里找?

typescript - 为什么我们在 TypeScript 中说装饰器?为什么不使用注释(如 Java)或属性(如 C#)?

ios - MapKit Direction to Selected 注释