Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在maven中构建scala java antlr项目会在运行时产生ClassDefNotFoundError_Java_Scala_Maven_Antlr - Fatal编程技术网

在maven中构建scala java antlr项目会在运行时产生ClassDefNotFoundError

在maven中构建scala java antlr项目会在运行时产生ClassDefNotFoundError,java,scala,maven,antlr,Java,Scala,Maven,Antlr,我正在尝试移植到scala2.10,并使用带有antlr3maven插件的maven构建它,而不是使用sbt。到目前为止,我得到了,代码编译成功。但是在运行时,当我尝试执行一些简单的操作,比如newmustach(“hello{{world}}!”),我会得到一个java.lang.NoClassDefFoundError 奇怪的是,首先,我得到了节点类的NoClassDefFoundError。我不明白为什么java类不在已编译的jar中,但我渴望测试它是否有效。因此,我用javac编译了两个

我正在尝试移植到
scala2.10
,并使用带有
antlr3maven插件的maven构建它,而不是使用sbt。到目前为止,我得到了,代码编译成功。但是在运行时,当我尝试执行一些简单的操作,比如
newmustach(“hello{{world}}!”)
,我会得到一个
java.lang.NoClassDefFoundError

奇怪的是,首先,我得到了
节点
类的NoClassDefFoundError。我不明白为什么java类不在已编译的jar中,但我渴望测试它是否有效。因此,我用
javac
编译了两个java类,并调用了scala 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>)
        ...
$scala-cp path/to/compiled/java/classes:path/to/jar-with-dependencies.jar
欢迎使用Scala版本2.10.2(OpenJDK 64位服务器虚拟机,Java1.7.0Ø21)。
键入要计算的表达式。
键入:有关详细信息的帮助。
scala>导入org.monkey.mustache_
导入org.monkey.mustache_
scala>新胡子(“你好{{{world}!”)
java.lang.NoClassDefFoundError:org/monkey/mustache/MustacheLexer
在org.monkey.mustache.mustache.(mustache.scala:21)
在org.monkey.mustache.mustache.(mustache.scala:32)
在。(:11)
在
在。(:7)
在
$print()
...
现在我在ANTLR输出类上得到一个NoClassDefFoundError,所以我看到不仅java文件编译输出没有打包在jar中,而且ANTLR生成的文件也没有打包。scala代码依赖于java代码以及ANTLR生成的代码,因此,如果编译成功,则一定意味着java和ANTLR代码在某个点上编译成功

相关maven输出随附:

$ 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] ------------------------------------------------------------------------
$mvn干净安装
.
. 忽略不相关的输出。。。
.
[信息]
[信息]------------------------------------------------------------------------
[信息]建筑物胡子2.10 1.0.5-快照
[信息]------------------------------------------------------------------------
[信息]
[信息]---maven clean插件:2.3:clean(默认清洁)@mustache_2.10---
[信息]删除文件集:/path/to/mustache.scala/target(包括:[**],不包括:[**])
[信息]
[信息]---antlr3 maven插件:1.0:antlr(默认)@mustache_2.10---
[信息]处理语法/path/to/mustache.scala/src/main/antlr/org/monkey/mustache/mustache.g
[信息]
[信息]---maven资源插件:2.3:resources(默认资源)@mustache_2.10---
[警告]使用平台编码(实际上是UTF-8)复制过滤后的资源,即构建依赖于平台!
[信息]跳过不存在的resourceDirectory/path/to/mustache.scala/src/main/resources
[信息]
[信息]——scala maven插件:3.1.3:compile(项目资源执行)@mustache_2.10---
[INFO]/path/to/mustache.scala/src/main/java:-1:INFO:编译
[INFO]/path/to/mustache.scala/target/generated sources/antlr:-1:INFO:编译
[INFO]/path/to/mustache.scala/src/main/scala:-1:INFO:编译
[信息]正在将8个源文件编译到/path/to/mustache.scala/target/classes,地址为1371141939993
[信息]在0秒内准备编译
[信息]在8秒内编译
[信息]
[信息]---maven编译器插件:3.1:compile(默认编译)@mustache_2.10---
[信息]无需编译-所有类都是最新的
[信息]
[信息]---maven编译器插件:3.1:compile(默认)@mustache_2.10---
[信息]无需编译-所有类都是最新的
[信息]
[信息]——scala maven插件:3.1.3:compile(compile)@mustache_2.10---
[INFO]/path/to/mustache.scala/src/main/java:-1:INFO:编译
[INFO]/path/to/mustache.scala/target/generated sources/antlr:-1:INFO:编译
[INFO]/path/to/mustache.scala/src/main/scala:-1:INFO:编译
[信息]正在将8个源文件编译到/path/to/mustache.scala/target/classes,地址为1371141948773
[信息]在0秒内准备编译
[信息]在8秒内编译
[信息]
.
. 忽略不相关的输出。。。
.
[信息]
[信息]---maven jar插件:2.2:jar(默认jar)@mustache_2.10---
[INFO]构建jar:/path/to/mustache.scala/target/mustache_2.10-1.0.5-SNAPSHOT.jar
[信息]
[信息]>>>maven源插件:2.2.1:jar(附加源)@mustache_2.10>>>
[信息]
[信息]---antlr3 maven插件:1.0:antlr(默认)@mustache_2.10---
[信息]未处理语法;生成的文件是最新的
[信息]

[INFO]scala编译器读取源代码*.java(在日志中显式),但不编译它们。要编译*.scala,可以使用*.java或*.class

生成到目标/生成源/antlr中的类不存在于目标/类中。编译不是由maven编译器插件完成的。错误使用includes:这是一个过滤器,不是添加源目录的方法。尝试删除它:将出现如下编译错误


…/MustacheLexer.java:[168,17]找不到符号
[错误]符号:变量类型

抱歉,我不知道/搜索如何修复它