请注意:虽然这个问题涉及名为Apache Camel的lib,但我认为这只是关于现代Grails插件如何工作的问题。
我在Grails 2.4.2上,我正在尝试使用带有Grails的Apache Camel,发现Grails Routing插件甚至无法安装它。
指示说要通过发出grails install-plugin routing
进行安装。当我这样做时,我得到:
grails install-plugin routing
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
.
|Environment set to development
......Warning
|
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":routing:1.3.2"
}
}
所以我像这样修改我的BuildConfig.groovy
:
plugins {
// plugins for the build system only
build ":tomcat:7.0.54"
compile ":routing:1.3.2"
...lots of other stuff omitted for brevity
}
然后插件说创建路由,发出grails create-route <RouteName>
。所以我这样做:
grails create-route OrderListener
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
|Running pre-compiled script
|Script 'CreateRoute' not found, did you mean:
1) CreateFilters
2) CreatePom
3) CreateApp_
4) CreateController
5) CreateHibernateCfgXml
Please make a selection or enter Q to quit:
这里发生了什么?!?我如何安装/使用此插件?!?我是否会失去理智,或者这个插件根本不起作用?
更新
我运行grails clean-all
,然后grails refresh-dependencies
然后grails create-route OrderListener
,我得到:
Loading Grails 2.4.2
.
|Environment set to development
.....Error
|
groovy.lang.MissingMethodException: No signature of method: CreateRoute.createArtifact() is applicable for argument types: () values: []
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
Error |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Error |
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
Error |
<huge stacktrace omitted>
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:68)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
Error |
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
Error |
... 68 more
答案 0 :(得分:2)
每当你在BuildConfig.groovy
进行更改时,请确保运行grails compile
以触发依赖项解析,这将下载新的和更新的插件和jar,并且它还将编译您的代码,这有助于确保事情至少是微不足道的。
但这里的核心问题是插件的CreateRoute.groovy
脚本严重受损。它缺少一个重要的包含,并且没有接近正确调用createArtifact
。作为一种解决方法,在作者解决此问题之前,请使用以下内容在应用的scripts
文件夹CreateCamelRoute.groovy
中创建一个脚本:
includeTargets << grailsScript('_GrailsCreateArtifacts')
target(createCamelRoute: "Creates a new Camel Route.") {
createArtifact(type: 'Route', path: 'grails-app/routes', name: argsMap.params?.get(0) ?: 'Example', suffix: 'Route')
}
setDefaultTarget(createCamelRoute)
它的故意命名与原版不同,因为如果Grails找到两个具有相同名称的名称,则会询问使用哪一个。这样你就可以运行
grails create-camel-route com.foo.bar.OrderListener
它会起作用。请注意,我更改了示例以包含一个包 - 始终使用包:)