ClassPathResource in a plugin does not resolve when WAR-ing

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ClassPathResource in a plugin does not resolve when WAR-ing

Konstantyn Smirnov
Hi all,

in my plugin project I have the following lines in the plugin-descriptor:

    def doWithSpring = {
     
      xmlParser XmlParser, false, false
     
      categoryTree( xmlParser:'parse' ){ bean ->
        bean.constructorArgs = [ new ClassPathResource( 'categoryTree.xml' ).inputStream ]
      }

    }

the file is located under src/java

when I run the plugin stand-alone with run-app, everything is perfect.
If I use run-war or deploy the war-file in tomcat, the file doesn't get resolved.

I tried both org.codehaus.groovy.grails.io.support.ClassPathResource and the original class from spring, neither worked.

What am I doing wrong?

TIA,
Konstantyn
Reply | Threaded
Open this post in threaded view
|

Re: ClassPathResource in a plugin does not resolve when WAR-ing

micke_
Hi

Could be that (like with maven/gradle) only java files under src directories for source code are included in the assembled artefact. Is the file in your assembled war?

Try putting the file in grails-app/conf

Cheers,
 Micke


On 25 May 2013 15:31, Konstantyn Smirnov <[hidden email]> wrote:
Hi all,

in my plugin project I have the following lines in the plugin-descriptor:

    def doWithSpring = {

      xmlParser XmlParser, false, false

      categoryTree( xmlParser:'parse' ){ bean ->
        bean.constructorArgs = [ new ClassPathResource( 'categoryTree.xml'
).inputStream ]
      }

    }

the file is located under src/java

when I run the plugin stand-alone with run-app, everything is perfect.
If I use run-war or deploy the war-file in tomcat, the file doesn't get
resolved.

I tried both org.codehaus.groovy.grails.io.support.ClassPathResource and the
original class from spring, neither worked.

What am I doing wrong?

TIA,
Konstantyn



--
View this message in context: http://grails.1312388.n4.nabble.com/ClassPathResource-in-a-plugin-does-not-resolve-when-WAR-ing-tp4645153.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: ClassPathResource in a plugin does not resolve when WAR-ing

Konstantyn Smirnov
This post was updated on .
no, everything under src/java gets included into the classpath, and yes, the file is present inside the war.

I also tried to define more verbosely:

    def doWithSpring = {
     
      xmlParser XmlParser, false, false
     
      categoryTreeFactory ClassPathResource, 'categoryTree.xml'
     
      categoryTreeFile categoryTreeFactory:'getFile'
     
      categoryTree( xmlParser:'parse' ){ bean ->
        bean.constructorArgs = [ ref( 'categoryTreeFile' ) ]
      }
    }

but it behaves the same way: in war the bean 'categoryTreeFile' is null.

I have pretty much the same stuff in a grails project (not plugin). I have a resource in src/java and in grails-app/conf/spring/resource.groovy the resource is resolved properly in run-app as well as in war

UPDATE:

can it be, that with run-war the doWithSpring section of plugin-descriptor is totally ignored?
Reply | Threaded
Open this post in threaded view
|

Re: ClassPathResource in a plugin does not resolve when WAR-ing

Konstantyn Smirnov
For now to make it work, I put the 'copy' of doWithSpring into conf/spring/resources.groovy:

beans = {
  MySpringSupport.beans.delegate = delegate
  MySpringSupport.beans.call()
}
but the solution of course is sub-optimal