How do I change the location of the Application.groovy class in Grails 3.0.3?

I created a new application in Grails 3.0.3 using the console:

grails create-app hello

      

and it works fine:

grails run-app

      

But now I would like to change the name of the package where Application.groovy resides (original location hello / grails-app / init / hello / Application.groovy) to something else like hello / grails-app / init / foo / Application.groovy. When I try to start the application after the change, there is an exception:

Error: Could not find or load main class hello.Application

      

Source of Application.groovy file (generated by grails besides package name)

package foo

import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration

class Application extends GrailsAutoConfiguration {
    static void main(String[] args) {
        GrailsApp.run(Application, args)
    }
}

      

Any hints where should I change something to rename this package?

EDIT: There is a snippet in the documentation:

grails-app/init/PACKAGE_PATH/Application.groovy The Application class used By Spring Boot to start the application

      

But still don't know what PACKAGE_PATH is and how to set it.

+3


source to share


4 answers


If the package statement matches the directory structure, it should just work. Run ./gradlew clean run

.



+3


source


After 2 hours of investigation and based on Jeff's answer, here is a detailed explanation:

  • I created a sample app named foo which createdgrails-app/init/foo/Application.groovy

  • I ran the app (using grails run-app

    ) and everything worked fine
  • Later I changed the package Application.groovy

    to com.test

    instead offoo

  • Error with error Could not find or load main class foo.Application

  • I kept trying grails clean

    and then grails run-app

    , but it didn't work because gradle build was not clean
  • I tried setting mainClassName

    or mainClass

    in build.gradle

    but nothing worked


Finally done ./gradlew clean

, it worked, so it is clear that grails clean

it doesn't actually clean up the gradle build.

For windows, just rungradlew.bat clean

+2


source


I ran it on Win10 and gradlew.bat clean run

didn't work for me, it said that there is no gradle task likerun

what helped me was, was gradlew.bat wrapper

that recreated some gradle scripts and then grails run-app

worked

0


source


And if that still doesn't work, kill the gradle daemons, run cleanup again, restart.

-1


source







All Articles