2017-04-26 8 views
0

現在、私は文法からANTLRパーサを生成し、そのパーサを自分のScalaコード内で使用したいプロジェクトに取り組んでいます。 - 予想通りのJavaソースがtarget/generated-sources/antlrに生成され生成されたJavaソースを混合されたscala-javaプロジェクトに追加します

<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>foo</groupId> 
    <artifactId>bar</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <name>${project.artifactId}</name> 
    <description>Foo</description> 

    <properties> 
    <maven.compiler.source>1.6</maven.compiler.source> 
    <maven.compiler.target>1.6</maven.compiler.target> 
    <encoding>UTF-8</encoding> 
    <scala.version>2.11.5</scala.version> 
    <scala.compat.version>2.11</scala.compat.version> 
    <antlr.version>4.7</antlr.version> 
    </properties> 

    <dependencies> 
    <dependency> 
     <groupId>org.scala-lang</groupId> 
     <artifactId>scala-library</artifactId> 
     <version>${scala.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.antlr</groupId> 
     <artifactId>antlr4-runtime</artifactId> 
     <version>${antlr.version}</version> 
    </dependency> 

    <!-- Test --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.specs2</groupId> 
     <artifactId>specs2-core_${scala.compat.version}</artifactId> 
     <version>2.4.16</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.scalatest</groupId> 
     <artifactId>scalatest_${scala.compat.version}</artifactId> 
     <version>2.2.4</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>net.alchim31.maven</groupId> 
      <artifactId>scala-maven-plugin</artifactId> 
      <version>3.2.1</version> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.0.2</version> 
     </plugin> 
     <plugin> 
      <groupId>org.antlr</groupId> 
      <artifactId>antlr4-maven-plugin</artifactId> 
      <version>${antlr.version}</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 
    <plugins> 
     <plugin> 
     <groupId>net.alchim31.maven</groupId> 
     <artifactId>scala-maven-plugin</artifactId> 
     <executions> 
      <execution> 
      <id>scala-compile-first</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>add-source</goal> 
       <goal>compile</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>scala-test-compile</id> 
      <phase>process-test-resources</phase> 
      <goals> 
       <goal>testCompile</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <executions> 
      <execution> 
      <phase>compile</phase> 
      <goals> 
       <goal>compile</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.18.1</version> 
     <configuration> 
      <useFile>false</useFile> 
      <disableXmlReport>true</disableXmlReport> 
      <!-- If you have classpath issue like NoDefClassError,... --> 
      <!-- useManifestOnlyJar>false</useManifestOnlyJar --> 
      <includes> 
      <include>**/*Test.*</include> 
      <include>**/*Suite.*</include> 
      </includes> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.antlr</groupId> 
     <artifactId>antlr4-maven-plugin</artifactId> 
     <executions> 
      <execution> 
      <id>antlr</id> 
      <goals> 
       <goal>antlr4</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <visitor>true</visitor> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

だけで正常に動作し、デフォルトの場所に文法ファイルを含むプロジェクトをコンパイルする:このため

は、私は次のPOMファイルを使用して新しいプロジェクトを設定しました。

しかし、私は私のScalaのコード内(のはFooParserそれを呼びましょう)生成されたパーサをインポートすることはできません - IntelliJのは FooParserと呼ばれるものがあることを認識するだけで、私は自動インポートにそれをしようとすると、それは失敗します。

でコマンドラインからビルドすると、FooParserに応じてソースコード が生成されません。

答えて

0

全部の解像度はかなりダムだった: 私のファイル構造が間違っていた:

src/ 
    main/ 
    antlr/ 
     Foo.g4 

あなたは適切なパッケージに、あなたの文法を配置する必要があり、そうでない場合 全部が適切に「インポート可能な」に文句を言いません。

src/ 
    main/ 
    antlr/ 
     packagename/ 
     Foo.g4 
関連する問題