How can I deploy a Grails 3.0.1
war file in, a non-embedded version of, Tomcat7? All I'm getting is a blank page or a 404 error. I can successfully deploy my other war files, so I know it's not a problem with Tomcat. My versions, and the steps I took are below:
Server version: Apache Tomcat/7.0.52 (Ubuntu)
Grails Version: 3.0.1
Groovy Version: 2.4.3
JVM Version: 1.7.0_80
I suspect that the problem has something to do with Spring framework or Gradle. I am not very familiar with either of them, but I did notice that 3.0.1 no longer uses a web.xml
and no longer has a Config.groovy
file. The site below details how to deploy a Grails project in 3.0.x.
http://grails.github.io/grails-doc/3.0.x/guide/deployment.html
grails run-app
and it deployed to localhost:8080
beautifully with no problems.I don't want to use the embedded version of Tomcat though. I'd like to deploy it to a different version of Tomcat, and this is where I am running into problems.
provided "org.springframework.boot:spring-boot-starter-tomcat"
grails war
website.war
to /var/lib/tomcat7/webapps
sudo service tomcat7 restart
to restart tomcatwebsite.war
unpacked automatically (it did)localhost:9999/website
^ This gives me is a blank white page.
website.war
and it's associated unpacked folder.
localhost:9999
website.war
on the manager appok
statuslocalhost:9999/website
^ This gives me the following error:
HTTP Status 404 - /website, The requested resource is not available.
Other relevant information:
https://grails.github.io/grails-doc/3.0.x/guide/single.html:
"Grails 3.0 no longer requires web.xml. Customizations can be done via Spring"
TheBuildConfig.groovy
file has also been changed.
Old Location:
grails-app/conf/BuildConfig.groovy
New Location:build.gradle
Description: Build time configuration is now defined in a Gradle build file
Other posts I've found: (sorry for not providing links, I cannot post more than two links without at least 10 reputation points.)
grails.org/wiki/Deployment#Tomcat
stackoverflow.com/questions/27557893/grails-app-deploy-in-tomcat-server-using-war-file-fails
Config.groovy
Grails 3.0.1
is now in Build.gradle
stackoverflow.com/questions/23664421/cant-deploy-grails-war-file-in-tomcat-results-in-404
Config.groovy
, which is no longer available in Grails 3.0.1
projectsEDIT:
When it unpacks the website.war
folder the catalina.out
log file shows this:
:: Spring Boot :: (v1.2.3.RELEASE)
Jun 07, 2015 3:01:23 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/website]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
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: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:147)
at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:47)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5456)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Jun 07, 2015 3:01:23 PM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /var/lib/tomcat7/webapps/website.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/website]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
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)
Jun 07, 2015 3:01:23 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9999"]
Jun 07, 2015 3:01:23 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 26775 ms
Then, when I try to load localhost:9999/website
the catalina.out
file shows this:
Jun 07, 2015 3:05:04 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-9999"]
Jun 07, 2015 3:05:04 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jun 07, 2015 3:05:04 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-9999"]
Jun 07, 2015 3:05:04 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-9999"]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common/classes], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/common], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server/classes], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/server], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.ClassLoaderFactory validateFile
WARNING: Problem with directory [/usr/share/tomcat7/shared], exists: [false], isDirectory: [false], canRead: [false]
Jun 07, 2015 3:05:06 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9999"]
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 576 ms
Jun 07, 2015 3:05:06 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 07, 2015 3:05:06 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
Jun 07, 2015 3:05:06 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/host-manager.xml
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/docs.xml
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/manager.xml
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/examples.xml
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Jun 07, 2015 3:05:07 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/website.war
Jun 07, 2015 3:05:07 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/website/WEB-INF/lib/tomcat-embed-core-8.0.20.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Jun 07, 2015 3:05:07 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/var/lib/tomcat7/webapps/website/WEB-INF/lib/tomcat-embed-el-8.0.20.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
Jun 07, 2015 3:05:07 PM org.apache.catalina.deploy.WebXml setVersion
WARNING: Unknown version string [3.1]. Default version will be used.
Deploy a WAR in TomEE The easiest way to add and deploy an application to TomEE is to drop the application package into a deployment directory. For that purpose you have available two directories: webapps and apps. To deploy an Application, just copy the WAR file into the webapps or apps directories.
Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.
In an effort to provide a more thorough answer, using the link provided by David Gonzalez Maline, Graeme references a documentation commit in GitHub.
Note that by default Grails will include an embeddable version of Tomcat inside the WAR file so that it is runnable (see the previous section), this can cause problems if you deploy to a different version of Tomcat. If you don't intend to use the embedded container then you should change the scope of the Tomcat dependencies to @provided@ prior to deploying to your production container in
build.gradle
:
provided "org.springframework.boot:spring-boot-starter-tomcat"
Source (emphasis mine)
In short, if you leave it at the default compile
scope, it will include two different versions of Tomcat, Tomcat 7 (which you are deploying to), and Tomcat 8 (which is provided by the spring-boot-starter-tomcat
).
The answer is here:
https://jira.grails.org/browse/GRAILS-12105
You need to declare the dependency to org.springframework.boot:spring-boot-starter-tomcat
as provided in build.gradle
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With