Groovy ShortTypeHandling ClassNotFoundException [英] Groovy ShortTypeHandling ClassNotFoundException
问题描述
我有一个使用groovy 2.2.1版的groovy应用程序。我的groovy应用程序以前运行良好,但最近开始抛出此异常:
at org.codehaus.groovy.runtime.callsite。 AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.app.Main.main(Main。 groovy:83)引起:java.lang.ClassNotFoundException:org.codehaus.groovy.runtime.typehandling.ShortTypeHandling $ b $在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)
在java .net.URLClassLoader $ 1.run(URLClassLoader.java:355)
ShortTypeHandling类甚至没有引入直到groovy 2.3.0。它如何在运行2.2.1版的groovy应用程序中引用?我可以通过在我的pom中用groovy-all-2.3.0.jar替换groovy-all-2.2.1.jar来解决这个问题,但这不会导致问题的根源。
ShortTypeHandling是在groovy-all-2.3.0.jar中引入的,所以快速解决方法是替换旧的groovy-all -xxxjar和groovy-all-2.3.0.jar。这解决了运行时ShorTypeHandling ClassNotFoundException,但通过在应用程序中引入新的groovy-all.jar依赖关系也创建了新问题。
真正的问题是groovy编译器通过maven调用。因为我介绍了需要groovy 2.0的spock,我需要更新groovy-eclipse-compiler依赖关系的maven条目。这里是更新的maven条目,用于处理groovy 2.x:
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 3.1< / version>
<配置>
< compilerId> groovy-eclipse-compiler< / compilerId>
<! - Java版本 - >
< source> 1.7< / source>
< target> 1.7< / target>
< / configuration>
<依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-eclipse-compiler< / artifactId>
< version> 2.8.0-01< / version>
< /依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-eclipse-batch< / artifactId>
<! - Groovy版本 - >
< version> 2.1.8-01< / version>
< /依赖关系>
< /依赖关系>
< / plugin>
有了这个功能,我可以像我最初一样使用groovy-all依赖/ b>
<依赖项>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
<! - 如果可能的话,如果在插件定义中匹配2.1.8,则更好 - >
<! - 但2.2.1在此处运行良好,并允许我保留原始pom定义 - >
< version> 2.2.1< / version>
< /依赖关系>
应用程序运行时不再引用ShortTypeHandling类,并且所有工作都像以前那样工作。
I have a groovy application that uses groovy version 2.2.1. My groovy app was previously running fine but has recently started throwing this exception:
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.app.Main.main(Main.groovy:83)Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.typehandling.ShortTypeHandling
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
The ShortTypeHandling class was not even introduced until groovy 2.3.0. How can it be referenced in a groovy app running version 2.2.1? I can solve this problem by replacing the groovy-all-2.2.1.jar with groovy-all-2.3.0.jar in my pom but that doesn't root cause the issue.
ShortTypeHandling was introduced in groovy-all-2.3.0.jar so the quick fix was to replace the older groovy-all-x.x.x.jar with groovy-all-2.3.0.jar. This solved the runtime ShorTypeHandling ClassNotFoundException but also created new problems by introducing a new groovy-all.jar dependency in the application.
The real issue was how the groovy compiler was being invoked via maven. Because I introduced spock which required groovy 2.0, I needed to update the maven entries for the groovy-eclipse-compiler dependency. Here are the updated maven entries for working with groovy 2.x:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- Java version -->
<source>1.7</source>
<target>1.7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<!-- Groovy version -->
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
With this in place, I could leave my groovy-all dependency the way I originally had it for the working/fully tested application like this:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- If possible, its better if this matches 2.1.8 in the plugin definition -->
<!-- but 2.2.1 worked fine here and allowed me to keep the original pom definition -->
<version>2.2.1</version>
</dependency>
The application runtime no longer references the ShortTypeHandling class and everything worked as it previously did.
这篇关于Groovy ShortTypeHandling ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!