Play framework java.lang.NoClassDefFoundError in dev mode only

I work with protobufs with a game platform 2.1.3 without problems. Then I needed to convert protobuffs to JSON, so I turned on

"com.googlecode.protobuf-java-format" % "protobuf-java-format" % "1.2" 

at Build.scala.

Trying to hide any protobuf for JSON using

 JsonFormat.printToString(message); 

This leads to the following error when starting in dev mode (starting from the playback 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] 

If playback starts in run mode, I have no errors.

I managed to get it to work in dev mode if I put the source code of the protobuf-java file in my application folder. This works as a workaround, but I would like to know the correct way to solve this problem.

Additional Information: As suggested below, I checked the game class, earned the dependencies, and searched my system, and I only have one copy of the included jar.

I can work without problems:

 Exception e = new InvalidProtocolBufferException() 

NoClassDefFoundError is thrown when I try to use some static method from protobuf-java library. For instance:

 XmlFormat.printToString(message) 

It does not work in dev mode, but it works in production mode (game start). Interestingly, a class that says it cannot find is different:

 [RuntimeException: java.lang.NoClassDefFoundError: com/google/protobuf/Message] 

I use the methods from the protobuf library without any problems elsewhere, so I know that they are included in the class path.

From google, I was able to find another instance that has similar problems: https://groups.google.com/forum/#!msg/play-framework/i0RNcu8PZOY/J7cy18xsg3oJ

I was not able to figure out how to refactor the code to make it work.

+3
source share
1 answer

Are you sure the class exists in 1.2? I see that it exists in version 2.3.

http://grepcode.com/file/repo1.maven.org/maven2/com.google.protobuf/protobuf-java/2.3.0/com/google/protobuf/InvalidProtocolBufferException.java

This seems like a problem with the loader, then where the protobuf-java-format banner is in one classloader that does not have access to another bank. It’s best to make sure that this ATM and another protobuf jar fall into the same directory when you run the application so that they end up in the same classloader.

Other things you can do is call class in each and get a cool loader and fool yourself by getting the parent-loader of the classes, and also see what the hierarchy of the loader class looks like.

Another very useful method for working with debugging is XXXXX.class.getProtectionDomain (). getCodeSource (). getLocation ()

replace XXXXX with a class existing in protobuf, like this Exception class, which has no problems loading your class, and the protobuf-java file has a loading problem, as well as any class from protobuf-java-format. This will tell you where the JVM loads the two banks.

0
source

Source: https://habr.com/ru/post/980584/


All Articles