简体   繁体   English

ANTLR4 CharStream 类丢失

[英]ANTLR4 CharStream class missing

I am using ANTLR4 to parse command lines for my Java Shell project.我正在使用 ANTLR4 来解析我的 Java Shell 项目的命令行。 When I run a JUnit test in VSCode, everything is fine.当我在 VSCode 中运行 JUnit 测试时,一切正常。 However, when I am building the Docker image and I try to run the shell in interactive mode, I get this error:但是,当我构建 Docker 映像并尝试以交互模式运行 shell 时,我收到此错误:

Error: Unable to initialize main class uk.ac.ucl.jsh.Jsh错误:无法初始化主类 uk.ac.ucl.jsh.Jsh

Caused by: java.lang.NoClassDefFoundError: org/antlr/v4/runtime/CharStream引起:java.lang.NoClassDefFoundError: org/antlr/v4/runtime/CharStream

Is there any issue with my pom.xml file, or is the problem coming from somewhere else?我的 pom.xml 文件有问题,还是问题来自其他地方? This is my pom.xml file:这是我的 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>uk.ac.ucl.jsh</groupId>
  <artifactId>jsh</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>jsh</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.antlr</groupId>
      <artifactId>antlr4-runtime</artifactId>
      <version>4.7.2</version>
    </dependency>
  </dependencies>
  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <argLine>-XX:MaxPermSize=512m</argLine>
  </properties>
  <build>
    <pluginManagement>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>3.0.0-M3</version>
            </plugin>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>0.8.4</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <configuration>
            <archive>
            <manifest>
              <mainClass>uk.ac.ucl.jsh.Jsh</mainClass>
            </manifest>
            </archive>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.antlr</groupId>
          <artifactId>antlr4-maven-plugin</artifactId>
          <version>4.7.2</version>         
          <executions>
            <execution>
              <goals>
                <goal>antlr4</goal>
              </goals>            
            </execution>
          </executions>
          <configuration>
              <visitor>true</visitor>
              <listener>true</listener>
              <outputDirectory>
                  ${basedir}/src/main/java/
              </outputDirectory>
            </configuration>    
        </plugin>          
      </plugins>
    </pluginManagement>
  </build>
  <reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
        </plugin>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <reportSets>
            <reportSet>
              <reports>
                <!-- select non-aggregate reports -->
                <report>report</report>
              </reports>
            </reportSet>
          </reportSets>
        </plugin>
    </plugins>
  </reporting>
</project>

This doesn't really look like an ANTLR problem.这看起来不像是 ANTLR 问题。 You'll need to look into how you're doing your build and how you're putting your Docker image together.您需要研究如何进行构建以及如何将 Docker 映像组合在一起。

There are a couple of solutions to this.对此有几种解决方案。

  • Look into how to have Maven produce an Uber jar (ie a jar file that bundles up all of it's dependencies)研究如何让 Maven 生成 Uber jar(即捆绑所有依赖项的 jar 文件)
  • Ensure that your Docker image has the ANTLR runtime included and in your class path.确保您的 Docker 映像包含 ANTLR 运行时并包含在您的类路径中。

The first of those is probably the more "normal" solutions these days.其中第一个可能是如今更“正常”的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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