grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 949 forks source link

Grails 3.0.1: CSS and JavaScript not rendering when deploying WAR to container #9008

Closed kschmit90 closed 9 years ago

kschmit90 commented 9 years ago

Windows 7 Grails 3.0.1

Am able to run the app and see CSS/JS when running from command line 'run-app', and am also able to see CSS/JS when running the JAR file with java -jar appName.jar.

I have tested this running a tomcat server locally, as well as a tomcat server running on a dedicated machine with the same results. Tomcat 7

However, when generating a WAR using the 'war' command, and deploying to a tomcat container the script and css link tags are left out of the header and no style is applied to the application.

Inside of the WAR I can see the assets directory with all of the css and js files.

I had the WAS_ENV property set to -Dgrails.env=PRODUCTION in the tomcat container.

In build.gradle - only the relevant bits...

buildscript {
    dependencies {
        // Using the newest version of asset-pipeline
        classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.2.3'
    }
}

apply plugin: "asset-pipeline"
apply plugin: "war"

assets {
    minifyJs = true
    minifyCss = true
}

// Because I saw this in another issue and thought it may help...
springBoot {
    providedConfiguration = "provided"
}

dependencies {
    runtime "org.grails.plugins:asset-pipeline"
    provided "org.springframework.boot:spring-boot-starter-tomcat"
}

All stylesheets are in grails-app/assets/stylesheets

All javascripts are in grails-app/assets/javascripts

All images are in grails-app/assets/images

grails-app/views/layouts/main.gsp

<!DOCTYPE HTML>
<html lang="en" class="no-js">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title><g:layoutTitle default="KnowledgeManagement"/></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <asset:stylesheet href="application.css"/>
    <asset:javascript src="application.js"/>
    <g:layoutHead/>
  </head>
  <body>

When I view the source of the deployed page this is what I see.

<!DOCTYPE HTML>
<html>
  <head>
    <title>Knowledge Asset Inventory</title>

  </head>
kschmit90 commented 9 years ago

'grails war' != 'grails gradle assemble'?

sanjaygir commented 6 years ago

can you please elaborate on the fix? I am observing the same problem. The styles seem to apply in development in my local machine but when deployed as war to production it doesnt apply the styles. I appreciate any help. Thanks!