这是对我之前的问题的重写,因为这令人困惑。基本上我有 groovy mix java maven 项目。我想在 java 文件中调用我的 groovy 类,我编写了类似这样的代码 import login.Login;
import groovy.lang.GroovyObject;
import groovy.net.xmlrpc.XMLRPCServerProxy;
public class TestConnectionServlet {
public String process(String parameter) throws {
GroovyObject groovyOject =new Login();//my groovy class
String sessionId ="";
try {
XMLRPCServerProxy serverProxy = (XMLRPCServerProxy) groovyOject.invokeMethod("getServerProxy", "https://myisteproxy");
sessionId = (String) groovyOject.invokeMethod("getSession",new Object[]{"username","password",serverProxy});
} catch(Exception e) {
Logger.error(this.getClass().getName(), "error during login", e);
}
System.out.println("session id.."+sessionId);
return null;
}
}
当我通过 main 方法运行它时,它运行良好,但是当我使用目标编译我的 Maven 项目时,clean install
它给了我错误,即 groovy 类不退出。我检查了我的构建路径src/main/groovy
是否已添加。我的 Maven 依赖项中有 groovy-all jar 下面是我的 Maven 依赖项
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-xmlrpc</artifactId>
<version>0.8</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<proc>none</proc>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.11</version>
</dependency>
</dependencies>
<configuration>
<sources>
<source>
<directory>${project.basedir}/src</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
</configuration>
</plugin>
</plugins>
</build>
请让我知道我错过了什么吗?