运行时建设的Maven结果斯卡拉-Java的ANTLR项目,ClassDefNotFoundErro

2019-10-18 05:52发布

我试图端口mustache.scala到scala 2.10 ,并使其与Maven的内置antlr3-maven-plugin ,而不是SBT。 到目前为止,我得到这个 ,代码编译成功。 但在运行时,当我试图执行一些简单的像new Mustach("hello {{world}}!")我得到一个java.lang.NoClassDefFoundError

奇怪的事情是,首先,我得到了NoClassDefFoundError的Node类。 我不明白为什么Java类的编译罐子were'nt,但我急于测试它是否工作。 所以我刚编两个Java类javac ,并援引了斯卡拉REPL如下:

$scala -cp path/to/compiled/java/classes:path/to/jar-with-dependencies.jar
Welcome to Scala version 2.10.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.monkey.mustache._
import org.monkey.mustache._

scala> new Mustache("hello {{world}}!")
java.lang.NoClassDefFoundError: org/monkey/mustache/MustacheLexer
        at org.monkey.mustache.Mustache.<init>(Mustache.scala:21)
        at org.monkey.mustache.Mustache.<init>(Mustache.scala:32)
        at .<init>(<console>:11)
        at .<clinit>(<console>)
        at .<init>(<console>:7)
        at .<clinit>(<console>)
        at $print(<console>)
        ...

所以现在我越来越对ANTLR输出班的NoClassDefFoundError,所以我看,不仅java文件编译输出并没有在包装罐,也ANTLR生成的文件。 斯卡拉代码依赖于Java代码以及在ANTLR生成的代码,所以如果编译成功,就一定意味着在某些时候Java和ANTLR代码被编译succefully。

相关行家输出连接:

$ mvn clean install
  .
  . irrelevant output omitted...
  .
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building mustache_2.10 1.0.5-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.3:clean (default-clean) @ mustache_2.10 ---
[INFO] Deleting file set: /path/to/mustache.scala/target (included: [**], excluded: [])
[INFO] 
[INFO] --- antlr3-maven-plugin:1.0:antlr (default) @ mustache_2.10 ---
[INFO] Processing grammar /path/to/mustache.scala/src/main/antlr/org/monkey/mustache/Mustache.g
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ mustache_2.10 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/mustache.scala/src/main/resources
[INFO] 
[INFO] --- scala-maven-plugin:3.1.3:compile (project-resources-execution) @ mustache_2.10 ---
[INFO] /path/to/mustache.scala/src/main/java:-1: info: compiling
[INFO] /path/to/mustache.scala/target/generated-sources/antlr:-1: info: compiling
[INFO] /path/to/mustache.scala/src/main/scala:-1: info: compiling
[INFO] Compiling 8 source files to /path/to/mustache.scala/target/classes at 1371141939993
[INFO] prepare-compile in 0 s
[INFO] compile in 8 s
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mustache_2.10 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default) @ mustache_2.10 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- scala-maven-plugin:3.1.3:compile (compile) @ mustache_2.10 ---
[INFO] /path/to/mustache.scala/src/main/java:-1: info: compiling
[INFO] /path/to/mustache.scala/target/generated-sources/antlr:-1: info: compiling
[INFO] /path/to/mustache.scala/src/main/scala:-1: info: compiling
[INFO] Compiling 8 source files to /path/to/mustache.scala/target/classes at 1371141948773
[INFO] prepare-compile in 0 s
[INFO] compile in 8 s
[INFO] 
  .
  . irrelevant output omitted...
  .
[INFO] 
[INFO] --- maven-jar-plugin:2.2:jar (default-jar) @ mustache_2.10 ---
[INFO] Building jar: /path/to/mustache.scala/target/mustache_2.10-1.0.5-SNAPSHOT.jar
[INFO] 
[INFO] >>> maven-source-plugin:2.2.1:jar (attach-sources) @ mustache_2.10 >>>
[INFO] 
[INFO] --- antlr3-maven-plugin:1.0:antlr (default) @ mustache_2.10 ---
[INFO] No grammars processed; generated files are up to date
[INFO] 
[INFO] <<< maven-source-plugin:2.2.1:jar (attach-sources) @ mustache_2.10 <<<
[INFO] 
[INFO] --- maven-source-plugin:2.2.1:jar (attach-sources) @ mustache_2.10 ---
[INFO] Building jar: /path/to/mustache.scala/target/mustache_2.10-1.0.5-SNAPSHOT-sources.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3:install (default-install) @ mustache_2.10 ---
[INFO] Installing /path/to/mustache.scala/target/mustache_2.10-1.0.5-SNAPSHOT.jar to /path/to/mustache_2.10/1.0.5-SNAPSHOT/mustache_2.10-1.0.5-SNAPSHOT.jar
[INFO] Installing /path/to/mustache.scala/pom.xml to /path/to/.m2/repository/org/monkey/mustache_2.10/1.0.5-SNAPSHOT/mustache_2.10-1.0.5-SNAPSHOT.pom
[INFO] Installing /path/to/mustache.scala/target/mustache_2.10-1.0.5-SNAPSHOT-sources.jar to /path/to/.m2/repository/org/monkey/mustache_2.10/1.0.5-SNAPSHOT/mustache_2.10-1.0.5-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29.516s
[INFO] Finished at: Thu Jun 13 19:46:06 IDT 2013
[INFO] Final Memory: 16M/214M
[INFO] ------------------------------------------------------------------------

BUTTOM线,请问如何从java文件编译输出的包装在瓶子随着编译Scala代码?

Answer 1:

Scala编译器读取源*的.java(明确在​​你的日志),但它不会编译它们。 要编译* .scala它可以使用*的.java OR的* .class。

生成到目标/生成-源/ ANTLR的类不存在到靶/类。 编译不受Maven的编译器插件中完成的。 使用错误包括:这是一个不过滤的方式添加源目录。 尝试删除它:你将有一个像编译错误

.../MustacheLexer.java:[168,17] cannot find symbol [ERROR] symbol : variable type

对不起,我不知道/搜索如何解决它。



文章来源: building a scala-java-antlr project in maven results with ClassDefNotFoundError on runtime