简体   繁体   English

如何在 Tomcat7 中部署 Grails 3.0.1 war 文件?

[英]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

  1. I ran 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,这就是我遇到问题的地方。

  1. I changed the scope of my Tomcat dependencies to provided:我将 Tomcat 依赖项的范围更改为提供:
    • provided "org.springframework.boot:spring-boot-starter-tomcat"
  2. I generated the war file using grails war我使用grails war生成了 war 文件
    • added website.war to /var/lib/tomcat7/webappswebsite.war添加到/var/lib/tomcat7/webapps
    • ran sudo service tomcat7 restart to restart tomcat运行sudo service tomcat7 restart重启 tomcat
    • checked to see if website.war unpacked automatically (it did)检查website.war是否自动解包(确实如此)
    • checked localhost:9999/website检查localhost:9999/website

^ This gives me is a blank white page. ^ 这给了我一个空白的白页。

  1. I deleted website.war and it's associated unpacked folder.我删除了website.war和它关联的解压文件夹。
    • checked localhost:9999检查localhost:9999
    • it successfully brought me to the default Tomcat screen它成功地将我带到了默认的 Tomcat 屏幕
    • signed into manager app登录经理应用
    • deployed website.war on the manager app在管理器应用程序上部署了website.war
    • it gave me the ok status它给了我ok状态
    • checked 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

  • This suggests putting a war in the webapps folder.这建议在 webapps 文件夹中放置一场战争。 I've already tried that and it's not working.我已经尝试过了,但它不起作用。

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

  • He is asking a very similar question but he is using a different version of Grails他问了一个非常相似的问题,但他使用的是不同版本的 Grails
  • The marked solution references Config.groovy标记的解决方案参考Config.groovy
  • However build time configuration in Grails 3.0.1 is now in Build.gradle然而, Grails 3.0.1构建时间配置现在在Build.gradle
  • I don't know if he successfully solved the problem.不知道他有没有成功解决问题。

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

  • Solution requires change to Config.groovy , which is no longer available in Grails 3.0.1 projects解决方案需要更改Config.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/websitecatalina.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.

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