How can I deploy a Grails 3.0.1 war file in Tomcat7?
Asked Answered
F

2

11

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

  1. I ran 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.

  1. I changed the scope of my Tomcat dependencies to provided:
    • provided "org.springframework.boot:spring-boot-starter-tomcat"
  2. I generated the war file using grails war
    • added website.war to /var/lib/tomcat7/webapps
    • ran sudo service tomcat7 restart to restart tomcat
    • checked to see if website.war unpacked automatically (it did)
    • checked localhost:9999/website

^ This gives me is a blank white page.

  1. I deleted website.war and it's associated unpacked folder.
    • checked localhost:9999
    • it successfully brought me to the default Tomcat screen
    • signed into manager app
    • deployed website.war on the manager app
    • it gave me the ok status
    • checked localhost: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

  • This suggests putting a war in the webapps folder. I've already tried that and it's not working.

https://mcmap.net/q/1018655/-grails-app-deploy-in-tomcat-server-using-war-file-fails

  • He is asking a very similar question but he is using a different version of Grails
  • The marked solution references Config.groovy
  • However build time configuration in Grails 3.0.1 is now in Build.gradle
  • I don't know if he successfully solved the problem.

https://mcmap.net/q/1018656/-can-39-t-deploy-grails-war-file-in-tomcat-results-in-404

  • Solution requires change to Config.groovy, which is no longer available in Grails 3.0.1 projects

EDIT:

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.
Fromm answered 5/6, 2015 at 20:0 Comment(2)
What does the catalina.out file for the Tomcat instance show after you've deployed it through the Web UI or through the copying into the webapps folder?Gradualism
I just added the catalina.out messages after I attempt to deploy website.war by copying it into the webapps folder.Fromm
P
7

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).

Pappy answered 16/9, 2015 at 16:50 Comment(4)
is it possible to tell it to use 'provided' rather that compile/runtime for certain dependencies depending on whether one wants a tomcat or embedded tomcat war ? i.e. not have to change the text by hand before doing a build ?Dresden
@Dresden I don't fully understand the question. Why would you want to have both options when creating a build? You could try using a command line variable to control whether things are compile or provided, but I haven't tried this. It would probably be a good question for the grails and gradle tags.Pappy
for example if Im doing a build for an external tomcat container I need 'provided' for some dependencies, and if im doing a build for our unit test server I simply want it as 'compile' and in that case I want it to run embeddedDresden
I leave mine as provided all the time, and I'm still able to run unit tests. Granted I'm using the grails test-app unit: command, rather than creating a build for a unit test server (I haven't heard of that arrangement before, I just have my CI machine run the tests before producing a war). Also, it is typically best if you can create one artifact from the build, so that whatever you use in test is the same as production.Pappy
S
4

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.

Solis answered 16/7, 2015 at 23:40 Comment(2)
welcome to SO. It's considered polite to explain, rather than pasting a link to the answer. Please consider editting your answer, so it will be more helpful to visitors.Circumfluent
Site is no longer availableAggressor

© 2022 - 2024 — McMap. All rights reserved.