Sagarmichael
Sagarmichael

Reputation: 1624

JAVA calsses used in grails as objects

Hi I have added my java classes to the

 projectName/src/java/MyClass.java

but i create an object in a service I have tried the following:

  def server = new MyClass();

  MyClass server = new MyClass();

The service cannot see the java class. Is there something more i need to do?

Upvotes: 0

Views: 50

Answers (1)

Multithreader
Multithreader

Reputation: 878

If the class is in the same package then you can use it right away. Otherwise, you have to import it.

Example:

if you have your MyClass.java as
------- MyClass.java -------------

package com.stackoverflow;
//rest of the class

------- end of MyClass.java ------

Then you can use it as
------- Mygroovy.groovy -----------------

import com.stackoverflow.MyClass  

//the rest of the code  

-----------end of Mygroovy.groovy -------

Upvotes: 1

Related Questions