0
votes

I am reading an image from web-app/images and creating a duplicate of same in same location with different name. A Grails Application.

I am getting the real path of the file using the follwing code,

    def serveletContext = ServletContextHolder.servletContext
    def filePath = serveletContext.getRealPath( "web-app/images" )
    def actFile= new File(filePath+ "myimg.png")
    final BufferedImage image = ImageIO.read(actFile)

This is working fine in my devlopment environment. Both read and write happening fine. When I am deploying WAR of the application in Tomcat i'm getting the exception

java.lang.reflect.UndeclaredThrowableException at BootStrap$_closure1.doCall(BootStrap.groovy:39) at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308) at grails.util.Environment.executeForEnvironment(Environment.java:301) at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: javax.imageio.IIOException: Can't read input file!

Please tell me how to resolve this. Or I can do the same by using relative path instead real path in anyway?

2
have u checked any permission related issues? if server is linux? - Daniel Adenew

2 Answers

0
votes

If you tested it on local and if is working. It might be due to server issue related to permission setting.

Please check the the permission on the tomcat webapps directory at least make sure it read and writeable to 755.

chmod u+x / 755 webapps

if not please add more code , to inspect your bug ,,, if you have used any other plugin also?

0
votes

Note that you need to deploy as a unpacked war otherwise getRealPath returns null on Tomcat. Under conf directory look at server.xml for unpackWARs attribute.

<Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="false">