Search code examples
javagrails

How to run java programs in grails?


I wrote a simple java program Hello.java, it looks like:

 public class Hello {
     public static void main(String[] args) {
         System.out.println("Hello ...");
     }
 }

I wanna it run under grails, so I created an app "hello", and put Hello.java under src/java, then run grails run-app, but when I click the "hello.HelloController" from http://localhost:8080/hello/, it shows the following errors:

Error 500: Internal Server Error
URI:/hello/hello/index  
Class:groovy.lang.MissingPropertyException 
Message:No such property: Hello for class: hello.HelloController 

The content of HelloController.groovy is:

class HelloController {

    def index() {
        Hello.main(null)
    }
}

Anybody could help me?


Solution

  • Try putting your Hello file in a package

    so inside src/java

    create a folder/package called test

    put Hello inside test

    import test.Hello
    
    class HelloController {
    
        def index() {
            Hello.main(null)
        }
    }