Outils pour utilisateurs

Outils du site


tech:langage_groovy

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:langage_groovy [2025/11/11 20:46] Jean-Baptistetech:langage_groovy [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 +<!DOCTYPE markdown>
 +{{tag>Java Langage CA}}
 +
 +# Langage Groovy
 +
 +Voir aussi :
 + * https://developers.redhat.com/articles/2023/07/06/how-use-debezium-smt-groovy-filter-routing-events
 +
 +
 +## Hello world
 +
 +~~~groovy
 +#! /usr/bin/env groovy
 +
 +/* 
 +This is an example
 +*/
 +
 +println "Hello World !"
 +~~~
 +
 +
 +## Importer une class
 +
 +~~~groovy
 +/*
 +#from java.util import Date
 +#from java.text import SimpleDateFormat
 +*/
 +
 +import java.util.Date
 +import java.text.SimpleDateFormat
 +~~~
 +
 +
 +## Fichier java .class
 +
 +`test.groovy`
 +~~~groovy
 +#! /usr/bin/env groovy
 +
 +println "Test1"
 +
 +class echo1 {
 +        def name;
 +        String hello() {
 +                println "Test2"
 +                return name
 +        }
 +}
 +
 +~~~
 +
 +~~~bash
 +groovyc test.groovy 
 +~~~
 +
 +~~~
 +$ strings test.class | grep -i test
 +test
 +test.groovy
 +Ltest;
 +Test1
 +
 +$ file *.class
 +echo1.class: compiled Java class data, version 49.0 (Java 1.5)
 +test.class:  compiled Java class data, version 49.0 (Java 1.5)
 +~~~
 +
 +~~~
 +$ groovy --classpath=. test
 +Test1
 +$ groovy --classpath=. test.groovy
 +Test1
 +~~~
 +
 +
 +
 +
 +## Pb 
 +
 +
 +
 +### Pb WARNING: An illegal reflective access operation has occurred
 +
 +~~~
 +WARNING: An illegal reflective access operation has occurred
 +WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/groovy/lib/groovy-2.4.21.jar) to method java.lang.Object.finalize()
 +WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
 +WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
 +WARNING: All illegal access operations will be denied in a future release
 +~~~
 +
 +
 +### Pb Error: Could not find or load main class test
 +
 +~~~
 +$ java -cp . test
 +Error: Could not find or load main class test
 +Caused by: java.lang.NoClassDefFoundError: groovy/lang/Script
 +~~~
 +
 +
 +#### Solution
 +
 +~~~bash
 +java -cp /usr/share/groovy/lib/groovy-2.4.21.jar:$PWD test
 +~~~
 +
 +
 +### Pb Error: Main method not found in class xxx
 +
 +~~~bash
 +$ java -cp /usr/share/groovy/lib/groovy-2.4.21.jar:$PWD echo1
 +Error: Main method not found in class echo1, please define the main method as:
 +   public static void main(String[] args)
 +or a JavaFX application class must extend javafx.application.Application
 +~~~
 +
 +#### Solution
 +
 +Voir : https://www.yawintutor.com/main-method-not-found-javafx-application-class/
 +
 +`test.groovy`
 +~~~groovy
 +#! /usr/bin/env groovy
 +
 +package com.plop;
 +
 +public class Hello {
 +        public static void main(String[] args) {
 +                System.out.println("Hello World");
 +        }
 +}
 +~~~
 +
 +~~~bash
 +java -cp /usr/share/groovy/lib/groovy-2.4.21.jar:$PWD com/plop/Hello
 +~~~
 +
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki