【发布时间】:2013-09-18 17:33:52
【问题描述】:
我正在使用带有 play framework 2.1.3 的 protobufs 没有问题。然后我需要将 protobufs 转换为 JSON,所以我包含了
"com.googlecode.protobuf-java-format" % "protobuf-java-format" % "1.2"
在 Build.scala 中。
试图将任何 protobuf 转换为 JSON 使用
JsonFormat.printToString(message);
这会导致在开发模式下运行时出现以下错误(从 play run 开始)
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.NoClassDefFoundError: com/google/protobuf/InvalidProtocolBufferException]]
...
Caused by: java.lang.NoClassDefFoundError: com/google/protobuf/InvalidProtocolBufferException
...
Caused by: java.lang.ClassNotFoundException: com.google.protobuf.InvalidProtocolBufferException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) ~[na:1.6.0_51]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_51]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:306) ~[na:1.6.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ~[na:1.6.0_51]
at sbt.PlayCommands$$anonfun$53$$anonfun$55$$anon$2.loadClass(PlayCommands.scala:535) ~[na:na]
如果在生产模式下开始播放,我没有任何错误。
如果我将 protobuf-java-format 的源代码放在我的应用程序文件夹中,我已经能够让它在开发模式下工作。作为一个临时解决方案,这是可行的,但我想知道处理这个问题的正确方法。
附加信息: 根据下面的建议,我检查了播放类路径、播放依赖项并搜索了我的系统,但我只包含了一份 jar 副本。
我可以毫无问题地运行:
Exception e = new InvalidProtocolBufferException()
当我尝试使用 protobuf-java-format 库中的任何静态方法时,会抛出 NoClassDefFoundError。例如:
XmlFormat.printToString(message)
在开发模式下不工作,但在生产模式下工作(播放开始)。有趣的是,它说它找不到的类是不同的:
[RuntimeException: java.lang.NoClassDefFoundError: com/google/protobuf/Message]
我在其他地方使用 protobuf 库中的方法没有问题,所以我知道它们被包含在类路径中。
从谷歌,我已经能够找到另一个有类似问题的实例: https://groups.google.com/forum/#!msg/play-framework/i0RNcu8PZOY/J7cy18xsg3oJ
我无法弄清楚如何重构代码以使其正常工作。
【问题讨论】:
标签: java json playframework protocol-buffers