简体   繁体   中英

Hosting grails app in tomcat

I did a very simple grails app and tried to push it to my tomcat.

I did:

grails war

and placed the resulting war file into my tomcat/webapps directory and restarted it. The war is named as ec2.war . I am able to hit localhost:8080 . But I am not able to hit: localhost:8080\\ec2 - I get an 404 error code.

I'm getting the following stacktrace in catalina.out :

NFO: Deploying web application archive /var/lib/tomcat7/webapps/ec2.war
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: stacktrace.log (Permission denied)
        at java.io.FileOutputStream.openAppend(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:207)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
        at org.apache.log4j.FileAppender.setFile(FileAppender.java:294)
        at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165)
        at org.apache.log4j.spi.OptionHandler$activateOptions.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
        at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.createFullstackTraceAppender(Log4jConfig.groovy:237)
        at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.configure(Log4jConfig.groovy:201)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.initialize(Log4jConfig.groovy:70)
        at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:48)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1599)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)

What can be causing this error and how can I resolve it?

Note that tomcat runs in ec2 and here localhost refers to my public IP which in case 5.xxxx .

You need to check the ownership of your tomcat folder. Do a:

ls -lisa /var/lib/tomcat7/webapps/

and check the ownership. If you just want to get it running, the easiest way is probably to do:

sudo chown -R root:root  /var/lib/tomcat
sudo chmod -R 777 /var/lib/tomcat

and do a

sudo /var/lib/tomcat/bin/startup.sh

But this is not the most secure way :)

By default a Grails application tries to create a log file named stacktrace.log in whatever was the current directory when tomcat started up. So you have two options

  1. Control which directory it starts up in, by putting a suitable cd in the startup script, and ensure that directory is writable by the user id that tomcat is running under or
  2. Change your grails configuration to put stacktrace.log somewhere else (or not to create it at all). You do this in the log4j closure in Config.groovy , see the "full stacktraces" section in the user guide chapter on logging config for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM