代码之家  ›  专栏  ›  技术社区  ›  Nandhi

在eclipse插件中使用ANTLR v4运行时

  •  0
  • Nandhi  · 技术社区  · 7 年前

    您好,我是eclipse插件开发的新手,我正在启动一个项目,将转换器合并到eclipse插件中,为此,我开始使用eclipse插件 hello word example 以及 example ,我可以编译我的项目并运行插件,但当我尝试加载解析器时,我得到了一个由java引起的异常。lang.NoClassDefFoundError:org/antlr/v4/runtime/CharStream“,我不知道可能是什么问题,我已经测试了解析器,但在插件环境之外,工作正常。

    我还试图合并maven来下载依赖项并运行antlr,所以我在pom中添加了这个。xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.plugin.helloworld</groupId>
      <artifactId>org.plugin.helloworld</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <dependencies>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId>
            <version>4.7.1</version>
        </dependency>
      </dependencies>
    
      <build>
        <defaultGoal>install</defaultGoal>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.antlr</groupId>
              <artifactId>antlr4-maven-plugin</artifactId>
              <version>4.7.1</version>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>4.7.1</version>      
            <configuration>
                <sourceDirectory>src/evaluator</sourceDirectory>
                <outputDirectory>src/evaluator</outputDirectory>
                <visitor>true</visitor>
                <listener>false</listener>
            </configuration>          
            <executions>
              <execution>
                <id>antlr</id>
                <goals>
                  <goal>antlr4</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
    

    我正在使用lexer和解析器,如下所示:

    public class SampleHandler extends AbstractHandler {
    
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
            IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    
            CharStream in = CharStreams.fromString("\"12*(5-6)\"");
            evaluatorLexer lexer = new evaluatorLexer(in);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            evaluatorParser parser = new evaluatorParser(tokens);
    
            MessageDialog.openInformation(
                    window.getShell(),
                    "Helloworld",
                    parser.eval().toString());
            return null;
        }
    }
    

    引用的库如下所示:

    enter image description here

    我设置了构建。属性如下

    source.. = src/
    output.. = bin/
    bin.includes = plugin.xml,\
                   META-INF/,\
                   .,\
                   icons/,\
                   lib/antlr4-runtime-4.7.1.jar,\
                   lib/ST4-4.0.8.jar,\
                   lib/antlr4-4.7.1.jar,\
                   lib/antlr4-runtime-4.7.1-sources.jar
    

    我在清单中读到了关于添加为捆绑包的内容,但我在依赖项选项卡中找不到该选项,只有在组织中。antlr。运行时不是v4。

    1 回复  |  直到 7 年前
        1
  •  1
  •   greg-449    7 年前

    您需要将罐子添加到 Bundle-Classpath 在清单中。MF。

    在清单中。MF编辑器在“运行时”选项卡上执行此操作。在“类路径”部分,单击“添加…”加上罐子,一定要留下“.”表示普通代码的条目。

    您的Bundle类路径应该最终看起来像:

    Bundle-ClassPath: .,
     lib/antlr4-runtime-4.7.1.jar,
     lib/ST4-4.0.8.jar,
     lib/antlr4-4.7.1.jar,
     lib/antlr4-runtime-4.7.1-sources.jar