how to use an existing class in java from grails?

2

I have a class in java that I intend to use from grails, what is the best way to do it?

    
asked by Paul 08.05.2016 в 18:17
source

1 answer

0

Your class made in Java must comply with the following:

  • Belong to a package.
  • Be declared public.
  • Have public members.

Here is an example of a class:

package edu.ltmj.prueba;

public class MiClase {
    public String saluda(String nombre) {
        return String.format("Hola %s", nombre);
    }
}

Then, you must pack this class in a jar. To do this, you must compile the class and generate the respective jar. For example if you have the package and the class inside a folder src , like this:

src
- edu
  - ltmj
    - prueba
      + MiClase.java

From the command line we can have the following:

$ cd /ruta/hacia/src
$ javac edu/ltmj/prueba/MiClase.java
$ jar -cvf miLib.jar edu/ltmj/prueba/MiClase.class

This will generate the jar with name miLib.jar and that will contain the class MiClase inside. You can import this jar into your groovy project and consume the classes and components that exist in your jar without problems. You can also generate the jar from your IDE (Eclipse, IntelliJ IDEA, NetBeans, etc).

    
answered by 09.05.2016 / 18:41
source