在Grails服务中放置@Grab注释的位置 [英] Where to put @Grab annotation in Grails Service
问题描述
但是,我想在grails的服务中重用它。
@Grab('net.sourceforge.nekohtml: nekohtml:1.9.18')
import org.cyberneko.html.parsers.SAXParser
def html ='''< p>
|我想尝试< span id =blk1> match< / span>内部
|的字符串< span id =blk2>在< / span>之间跨度标签< span>其中< / span>
|< / p>'''。stripMargin()
def content = new XmlSlurper(new SAXParser()).parseText(html)
列表< ;字符串> span = content。'**'。findAll {it.name()=='SPAN'&& it。@ id?.text()?. startsWith('blk')} *。text()
ATTEMPT1:
import groovy.grape.Grape;
@Grab('net.sourceforge.nekohtml:nekohtml:1.9.18')
class MyService {
// ..
}
ERR:
*** java.lang.instrument ASSERTION FAILED ***:!errorOutstandingwith message can not create byte arrau at ../../../src/share/instrument/JPLISAgent .c行:793
我试图将@Grab注释放在方法之前,应该做上面的代码,我有错误。
我试图把@Grab放在上课前,结果相同;这也是一个错误。
我在哪里放置@Grab注释。
ATTEMPT2: >
当我在BuildConfig.groovy中添加上面的依赖项,
runtime(' net.sourceforge.nekohtml:nekohtml:1.9.18')
ERR:
i得到以下错误:
grails> --stacktrace -Dserver.port = 9090 run-app
|包装Grails应用程序.....
|错误运行脚本错误--stacktrace -Dserver.port = 9090 run-app:org / apache / xerces / dom / DeferredElementNSImpl(注意:堆栈跟踪已被过滤,使用--verbose查看整个跟踪。)
java .lang.NoClassDefFoundError:org / apache / xerces / dom / DeferredElementNSImpl
在org.apache.xerces.dom.DeferredDocumentImpl.getNodeObject(未知源)
在org.apache.xerces.dom.DeferredDocumentImpl.synchronizeChildren (未知来源)
在org.apache.xerces.dom.CoreDocumentImpl.getDocumentElement(未知来源)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在_GrailsPackage_groovy $ _run_closure5.doCall(_GrailsPackage_groovy:74)
在org.springsource.loaded.ri.ReflectiveInterceptor。 jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(Gan tMetaClass.java:133)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant .GantBinding.withTargetEvent(GantBinding.groovy:90)
在org.codehaus.gant.GantBinding.this $ 4 $ withTargetEvent(GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke( ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _ini tializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16.doCall( GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在_GrailsPackage_groovy $ _run_closure2.doCall(_GrailsPackage_groovy:58)
在org.springsource.loaded.ri.ReflectiveInterceptor .jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java :1243)
在org.codehaus.ga nt.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
在org.springsource.loaded.ri.ReflectiveInterceptor。 jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java: 1243)
在org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
在org.codehaus.gant.GantBinding.this $ 4 $ withTargetEvent(GantBinding.groovy)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
在org.springsource。 loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveIn terceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.processClosure(GantMetaClass.java:81)
在org.codehaus.gant.GantMetaClass.processArgument(GantMetaClass.java:95)
在org.codehaus .GantMetaClass.invokeMethod(GantMetaClass.java:128)
在RunApp $ _run_closure1.doCall(RunApp.groovy:30)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java :1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure 5_closure16_closure18.doCall(GantBinding.groovy:185)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16_closure18.doCall( GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
在org.codehaus.gant.GantBinding.this $ 4 $ withTargetEvent(GantBinding.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org。 codehaus.gant.GantBinding $ _initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在org.codehaus.gant。 GantBinding $ _initializeGantBinding_closure5_closure16.doCall(GantBinding.gr oovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在gant.Gant $ _dispatch_closure5.doCall(Gant.groovy:381)
在org .springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
在gant.Gant $ _dispatch_closure7.doCall(Gant.groovy:415)
在org.springsource.loaded.ri.ReflectiveInterceptor .jlrMethodInvoke(ReflectiveInterceptor.java:1243)
at gant.Gant $ _dispatch_closure7.doCall(Gant.groovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)$ gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this $ 2 $ withBuildListeners(Gant.groovy)
at gant.Gant $ this $ 2 $ withBuildListeners.callCurrent(未知来源)
at gant.Gant $ this $ 2 $ withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this $ 2 $讯(Gant.g roovy)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets (Gant.groovy:591)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
at gant.Gant.executeTargets(Gant.groovy:590)
在org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243)
|错误运行脚本错误--stacktrace -Dserver.port = 9090 run-app:org / apache / xerces / dom / DeferredElementNSImpl
ATTEMPT3:
同样,在BuildConfig.groovy中添加依赖关系也没有解决问题。
依赖关系{
/ pre>
// ....
// .......
compile('net.sourceforge.nekohtml:nekohtml:1.9.18'){
excludedes'xercesImpl'
}
}
即使我使用上面的解决方案,它只在编译时有效。
ATTEMPT4 :
我执行以下命令添加依赖关系;但是无效:grails install-dependency net.sourceforge.nekohtml:nekohtml:1.9.18 --dir = lib
ERR
我得到这个错误信息:包装Grails应用程序.....
|错误错误运行脚本run-app:org / apache / xerces / dom / DeferredElementNSImpl(使用--stacktrace查看完整的跟踪)
解决方案将所有库放在最佳做法中:
在
lib
文件夹中,然后Refersh或
或
- 在
conf / BuildConfig.groovy
Hiowever,如果你想使用葡萄,使用以下语法:
import groovy.grape.Grape
Grape.grab(group:'net .sourceforge.nekohtml',module:'nekohtml',version:'1.9.18')
groovy.grape.Grape.initGrape()
@Grab(group ='net.sourceforge.nekohtml' module ='nekohtml',version ='1.9.18')
public class MyService {
}
I have the following groovy code ,and i excute it on grails console plugin . it works fine . However, i want to reuse it in grails' service.
@Grab( 'net.sourceforge.nekohtml:nekohtml:1.9.18' ) import org.cyberneko.html.parsers.SAXParser def html = '''<p> | I wanted to try to <span id="blk1">match</span> the inner part | of the string<span id="blk2"> between </span> the span tags <span>where</span> |</p>'''.stripMargin() def content = new XmlSlurper( new SAXParser() ).parseText( html ) List<String> spans = content.'**'.findAll { it.name() == 'SPAN' && it.@id?.text()?.startsWith( 'blk' ) }*.text()
ATTEMPT1:
import groovy.grape.Grape; @Grab( 'net.sourceforge.nekohtml:nekohtml:1.9.18' ) class MyService { //.. }
ERR :
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create byte arrau at ../../../src/share/instrument/JPLISAgent.c line: 793
i tried to put @Grab annotation before method that shall do the code above, i have an error. i tries to put @Grab before class ,the same result; it's an error also .
Where do i put @Grab annotation .
ATTEMPT2:
When i add the dependency above in BuildConfig.groovy ,
runtime( 'net.sourceforge.nekohtml:nekohtml:1.9.18')
ERR : i get the following error :
grails> --stacktrace -Dserver.port=9090 run-app | Packaging Grails application..... | Error Error running script --stacktrace -Dserver.port=9090 run-app: org/apache/xerces/dom/DeferredElementNSImpl (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.) java.lang.NoClassDefFoundError: org/apache/xerces/dom/DeferredElementNSImpl at org.apache.xerces.dom.DeferredDocumentImpl.getNodeObject(Unknown Source) at org.apache.xerces.dom.DeferredDocumentImpl.synchronizeChildren(Unknown Source) at org.apache.xerces.dom.CoreDocumentImpl.getDocumentElement(Unknown Source) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at _GrailsPackage_groovy$_run_closure5.doCall(_GrailsPackage_groovy:74) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90) at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at _GrailsPackage_groovy$_run_closure2.doCall(_GrailsPackage_groovy:58) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90) at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.processClosure(GantMetaClass.java:81) at org.codehaus.gant.GantMetaClass.processArgument(GantMetaClass.java:95) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:128) at RunApp$_run_closure1.doCall(RunApp.groovy:30) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90) at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:591) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) at gant.Gant.executeTargets(Gant.groovy:590) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1243) | Error Error running script --stacktrace -Dserver.port=9090 run-app: org/apache/xerces/dom/DeferredElementNSImpl
ATTEMPT3: Likewise,adding the dependency in BuildConfig.groovy did not solve the problem.
dependencies { //.... // ....... compile( 'net.sourceforge.nekohtml:nekohtml:1.9.18'){ excludes 'xercesImpl' } }
Even i use the solution above, it works only when compiling.
ATTEMPT4: I execute the following command to add the dependency ; but in vain :
grails install-dependency net.sourceforge.nekohtml:nekohtml:1.9.18 --dir=lib
ERR And i get , this error message :
Packaging Grails application..... | Error Error running script run-app: org/apache/xerces/dom/DeferredElementNSImpl (Use --stacktrace to see the full trace)
解决方案Best practices to Put all libraries either :
in
lib
folder then Refersh , or inor
- in
conf/BuildConfig.groovy
Hiowever , if you want to use Grape , Use the following syntax:
import groovy.grape.Grape Grape.grab(group:'net.sourceforge.nekohtml', module:'nekohtml', version:'1.9.18')
or
groovy.grape.Grape.initGrape() @Grab(group='net.sourceforge.nekohtml', module='nekohtml', version='1.9.18') public class MyService{ }
这篇关于在Grails服务中放置@Grab注释的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!