Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've created new application in Grails 3.0.3 using console:

grails create-app hello

and it's running fine with:

grails run-app

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

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

Source of the Application.groovy file is (generated by grails, except 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 be able to rename this package?

EDIT: In the documentation there is a fragment:

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

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

like image 447
Piotr Chowaniec Avatar asked Jul 23 '15 09:07

Piotr Chowaniec


2 Answers

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

like image 90
Jeff Scott Brown Avatar answered Sep 29 '22 09:09

Jeff Scott Brown


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

  1. I created a sample app named foo which created the grails-app/init/foo/Application.groovy
  2. I ran the app (using grails run-app) and things worked fine
  3. Later I changed the package of Application.groovy to com.test instead of foo
  4. It failed with error Could not find or load main class foo.Application
  5. I kept trying grails clean and then grails run-app but it didn't work because gradle build was not clean
  6. I tried setting mainClassName or mainClass under build.gradle but nothing worked

Finally doing ./gradlew clean made it to work so it is clear that grails clean is not actually cleaning the gradle build.

For windows, just run gradlew.bat clean

like image 32
Shashank Agrawal Avatar answered Sep 29 '22 10:09

Shashank Agrawal