伴随着许多类解析错误,我的项目突然开始在包上显示这个错误:
无法解析类型groovy.lang.MetaClass。它是从所需的.class文件间接引用的-无法解析类型groovy.lang.GroovyObject。它是从所需的.class文件间接引用的
我还注意到单元测试都无法在TestFor注释上编译和显示此错误:
- Groovy:class TestFor is not an annotation in @TestFor
- Groovy:unable to resolve class TestFor , unable to find class for
annotation
我
Groovy中有没有一种方法可以从JDK11模块中导入代码?到目前为止,groovyc无法编译,在导入JavaFX模块的代码时遇到错误。如果导入JavaFX,我甚至无法获得要编译的HelloWorld groovy脚本。
这样的命令会失败:
./groovy3/groovy-3.0.0-beta-2/bin/groovyc grscript.groovy -j -Fmodule-path=/usr/share/openjfx/lib/ -Fadd-modules=javafx.controls:javafx.base
Gives the error:
unable to resolve c
我在使用GroovyScriptEngine时遇到了一个问题--它似乎无法处理内部类。有人知道GroovyScriptEngine或解决方案是否有一些限制吗?
我有一个包含这两个文件的目录:
// MyClass.groovy
public class MyClass {
MyOuter m1;
MyOuter.MyInner m2;
}
和
// MyOuter.groovy
public class MyOuter {
public static class MyInner {}
}
我有以下的考试课程:
import java.io.File;
import
我想编写一个polyline类,它需要来自行和圆弧类的功能。我知道polyline有线条和圆弧,因此我应该使用一个接口而不是扩展(我知道你不能扩展两个类)。问题是,我还需要为行类和圆弧类编写代码,如果可能的话,我希望避免在polyline类中重复这段代码。
有办法这样做吗?
下面是行类中的代码片段。polyline类还需要有getMidPoint()、containsPoint(x、y)等。我还没有编写圆弧代码,但它具有类似的功能getMidPoint()、containsPoint(x,y)。
public Line (double x1,double y1, double x2,doubl
我有一个Groovy文件,看起来如下(当前)。
main.groovy
import org.packages.mystuff.JavaClassIAmUsing;
public class MyObject {
def rate(item){
def o = evaluate(new File (new File(getClass().protectionDomain.codeSource.location.path).parent),"CommonFunctions.groovy");
println o.whoami();
我在Linux机器上安装了最新版本的Java (HotSpot VM 1.7.0_45),并使用Gradle 1.8。我还安装了Groovy 1.8.6版本,但我认为这并不重要,因为Gradle有自己的groovy-all.jar。
我的问题是,我无法使用gradle编译Groovy项目,因为JavaFX类似乎不在类路径中。这些错误如下:
unable to resolve class javafx.scene.Node
@ line 3, column 1.
import javafx.scene.Node
最后,我将以下可怕的硬编码路径添加到我的依赖项中,从而修复了这个问题:
co
当我通过命令行或Jenkins运行Groovy脚本时,我得到一个"unable to resolve class“错误。
我在C:\Users\myuser\git\productname\mycompany-build\src\main\groovy\com\mycompany\build的同一文件夹中有以下两个groovy文件
Foo.groovy
package com.mycompany.build
class Foo {
Foo() {
}
public void runBar() {
Bar bar = new Bar();
bar.nam
我有两节课。One.groovy:
class One {
One() {}
def someMethod(String hey) {
println(hey)
}
}
和Two.groovy:
class Two {
def one
Two() {
Class groovy = ((GroovyClassLoader) this.class.classLoader).parseClass("One.groovy")
one = groovy.newInstance()
one.someMethod("Yo!&
安装导出插件后,我无法运行grails应用程序并获得以下信息
java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.pri
我有一个带有多个groovy文件的项目,我有几个“小”类,我想把它们放在一个文件中。
基本上,我想要的是:
Foo.groovy:
class Foo
{
Foo() { println "Foo" }
}
Bar.groovy:
class Bar
{
Bar() { println "Bar" }
}
class Baz
{
Baz() { println "Baz" }
}
script.groovy:
#!/groovy/current/bin/groovy
new Foo()
new Bar()
new Ba
最近,我在帮助迁移一些遗留代码时遇到了这个问题。
以下内容用于在Groovy2.4.x中正确执行:
class Person {
String name
}
def me = new Person( name : 'Joe' )
assert me.(name) == 'Joe'
当在Groovy 3.0.2上执行时,它会引发异常:
groovy.lang.MissingPropertyException:没有这样的属性:类名称: MyScript
括在括号中的属性名称在我看来是不对的:事实上,在旧版本中也没有出现异常,这让我感到惊讶。
我可能会使用的语
我是groovy的新手,我做了一个有一些常量的java类。
public class test{
public static final constant1 ="hello"
}
现在在我的groovy代码中,我只想把这个常量放到一个映射中。
Map<String, String> map1 = new HashMap();
map1.put("hello", test.constant1);
我得到了一个groovy.lang.MissingPropertyException错误,说没有这样的属性:测试类。
这个错误说明
我已经创建了一个Grails 3.3.8项目。数据源(Oracle)配置在application.yml文件中成功完成。但是,当我在groovy类中使用数据源时,我会遇到以下错误:
Caused by GroovyRuntimeException: Ambiguous method overloading for method groovy.sql.Sql#<init>.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface jav
在groovy中看到了很好的使用。
问题:,但是,当将它与关键字this.with{.}组合使用时,有问题或无法理解为什么不提供期望的输出,如下所示:
以下是Person.groovy的代码
class Person {
def name
def address
def mail
Person(name, address, mail){
this.with {
name = name
address = address
mail = mail
}
我有一组用以下代码保存到数据库中的日期(我不能更改):
Date date = new Date()
save(date)
在groovy中有没有一种简单的方法来重新格式化和显示用户本地时区的日期?比如..。
dateCreated.format('h:mm a MMMM dd, yyyy', Locale.US)
Groovy中没有内置这样的东西吗?是唯一的解决方案吗?
import java.text.SimpleDateFormat
String date = dateCreated.format('h:mm a MMMM dd, yyyy')
def
我有一个带有实用程序方法的脚本,我想从我的其他脚本访问它。
我在java代码中像这样加载脚本。
static {
GroovyShell shell = new GroovyShell();
//This is the script that has the utility
groovyUtils = shell.parse(new InputStreamReader(MyJavaClass.class.getResourceAsStream("scripts/json/MyUtils.groovy")));
//This is the scr
我们正在应用程序中评估解释器(v2.4),以便动态执行标准Java语法。
早些时候,我们使用了Java解释器,但是它有一个在高负载下的BeanShell,这促使我们寻找一种替代方法,比如Groovy。
示例Java代码
static String script = "int y = x * x; System.out.println(\"** value of y ** :: \" + y ); ";
GroovyShell gs = new GroovyShell();
Script evalScript = gs.parse("void evalM
我正在努力弄清楚如何在运行时在java中加载两个协同依赖的Groovy脚本。如果我有两个groovy脚本,如:
A.groovy
import B
class A {
A() {
B b = new B()
}
}
B.groovy
import A
class B {
B() {
A a = new A()
}
}
我希望将它们作为java类加载,但是当我运行时:
ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoade