tech:langage_groovy
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:langage_groovy [2025/11/11 20:46] – Jean-Baptiste | tech:langage_groovy [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Langage Groovy | ||
| + | |||
| + | Voir aussi : | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ## Hello world | ||
| + | |||
| + | ~~~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 | ||
| + | #! / | ||
| + | |||
| + | println " | ||
| + | |||
| + | class echo1 { | ||
| + | def name; | ||
| + | String hello() { | ||
| + | println " | ||
| + | return name | ||
| + | } | ||
| + | } | ||
| + | |||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | groovyc test.groovy | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ strings test.class | grep -i test | ||
| + | test | ||
| + | test.groovy | ||
| + | Ltest; | ||
| + | Test1 | ||
| + | |||
| + | $ file *.class | ||
| + | echo1.class: | ||
| + | test.class: | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ 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:/ | ||
| + | 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: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Solution | ||
| + | |||
| + | ~~~bash | ||
| + | java -cp / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Pb Error: Main method not found in class xxx | ||
| + | |||
| + | ~~~bash | ||
| + | $ java -cp / | ||
| + | Error: Main method not found in class echo1, please define the main method as: | ||
| + | | ||
| + | or a JavaFX application class must extend javafx.application.Application | ||
| + | ~~~ | ||
| + | |||
| + | #### Solution | ||
| + | |||
| + | Voir : https:// | ||
| + | |||
| + | `test.groovy` | ||
| + | ~~~groovy | ||
| + | #! / | ||
| + | |||
| + | package com.plop; | ||
| + | |||
| + | public class Hello { | ||
| + | public static void main(String[] args) { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | java -cp / | ||
| + | ~~~ | ||
| + | |||
