[英]How can I deploy a Grails 3.0.1 war file in Tomcat7?
How can I deploy a Grails 3.0.1
war file in, a non-embedded version of, Tomcat7?如何在 Tomcat7 的非嵌入式版本中部署
Grails 3.0.1
war 文件? All I'm getting is a blank page or a 404 error.我得到的只是一个空白页或 404 错误。 I can successfully deploy my other war files, so I know it's not a problem with Tomcat.
我可以成功部署我的其他war文件,所以我知道这不是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.我怀疑问题与Spring框架或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.我对它们中的任何一个都不是很熟悉,但我确实注意到 3.0.1 不再使用
web.xml
并且不再有Config.groovy
文件。 The site below details how to deploy a Grails project in 3.0.x.下面的站点详细介绍了如何在 3.0.x 中部署 Grails 项目。
http://grails.github.io/grails-doc/3.0.x/guide/deployment.html 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.grails run-app
并将它部署到localhost:8080
,没有任何问题。 I don't want to use the embedded version of Tomcat though.不过,我不想使用 Tomcat 的嵌入式版本。 I'd like to deploy it to a different version of Tomcat, and this is where I am running into problems.
我想将它部署到不同版本的 Tomcat,这就是我遇到问题的地方。
provided "org.springframework.boot:spring-boot-starter-tomcat"
grails war
grails war
生成了 war 文件
website.war
to /var/lib/tomcat7/webapps
website.war
添加到/var/lib/tomcat7/webapps
sudo service tomcat7 restart
to restart tomcatsudo service tomcat7 restart
重启 tomcatwebsite.war
unpacked automatically (it did)website.war
是否自动解包(确实如此)localhost:9999/website
localhost:9999/website
^ This gives me is a blank white page. ^ 这给了我一个空白的白页。
website.war
and it's associated unpacked folder.website.war
和它关联的解压文件夹。
localhost:9999
localhost:9999
website.war
on the manager appwebsite.war
ok
statusok
状态localhost:9999/website
localhost:9999/website
^ This gives me the following error: ^ 这给了我以下错误:
HTTP Status 404 - /website, The requested resource is not available.
HTTP 状态 404 - /website,请求的资源不可用。
Other relevant information:其他相关资料:
https://grails.github.io/grails-doc/3.0.x/guide/single.html : 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"
“Grails 3.0 不再需要 web.xml。自定义可以通过 Spring 完成”
The BuildConfig.groovy
file has also been changed. BuildConfig.groovy
文件也已更改。
Old Location:
grails-app/conf/BuildConfig.groovy
New Location:build.gradle
Description: Build time configuration is now defined in a Gradle build file旧位置:
grails-app/conf/BuildConfig.groovy
新位置:build.gradle
描述:构建时间配置现在在 Gradle 构建文件中定义
Other posts I've found: (sorry for not providing links, I cannot post more than two links without at least 10 reputation points.)我发现的其他帖子:(抱歉没有提供链接,如果没有至少 10 个声望点,我不能发布两个以上的链接。)
grails.org/wiki/Deployment#Tomcat grails.org/wiki/Deployment#Tomcat
stackoverflow.com/questions/27557893/grails-app-deploy-in-tomcat-server-using-war-file-fails stackoverflow.com/questions/27557893/grails-app-deploy-in-tomcat-server-using-war-file-fails
Config.groovy
Config.groovy
Grails 3.0.1
is now in Build.gradle
Grails 3.0.1
构建时间配置现在在Build.gradle
stackoverflow.com/questions/23664421/cant-deploy-grails-war-file-in-tomcat-results-in-404 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
projectsConfig.groovy
,这在Grails 3.0.1
项目中不再可用EDIT:编辑:
When it unpacks the website.war
folder the catalina.out
log file shows this:当它解压
website.war
文件夹时, catalina.out
日志文件显示:
:: 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:然后,当我尝试加载
localhost:9999/website
, catalina.out
文件显示:
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.
In an effort to provide a more thorough answer, using the link provided by David Gonzalez Maline, Graeme references a documentation commit in GitHub.为了提供更彻底的答案,使用 David Gonzalez Maline 提供的链接,Graeme 引用了 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.
请注意,默认情况下,Grails 将在 WAR 文件中包含一个可嵌入版本的 Tomcat,以便它可以运行(请参阅上一节),如果您部署到不同版本的 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
:如果您不打算使用嵌入式容器,那么在部署到
build.gradle
的生产容器之前,您应该将 Tomcat 依赖项的范围更改为 @provided@ :
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
).简而言之,如果您将其保留在默认
compile
范围内,它将包括两个不同版本的 Tomcat,Tomcat 7(您要部署到该版本)和 Tomcat 8(由spring-boot-starter-tomcat
)。
The answer is here:答案在这里:
https://jira.grails.org/browse/GRAILS-12105 https://jira.grails.org/browse/GRAILS-12105
You need to declare the dependency to org.springframework.boot:spring-boot-starter-tomcat
您需要声明对
org.springframework.boot:spring-boot-starter-tomcat
的依赖
as provided in build.gradle
.如
build.gradle
提供的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.