简体   繁体   中英

can a java class extend from a groovy class?

Hello everyone i am trying out groovy and have a question as to whether a java class can extend from a groovy class and if so what will be the project structure in a maven project. i have tried adding groovy eclipse compiler plugin to pom file (and after resolving the "Plugin execution not covered by lifecycle configuration errors" by ignoring via quickfix) but some how my groovy class is never referenced from my java class and so i cant extend my java class. the reason behind this is that i am exploring groovy property and method missing feature to support some level of dynamic behavior in a project of mine. the groovy and java source files are all under the same folder src/main/java and within the same package. Need help.

Yes, you may intermix Java and Groovy sources in a project and have source dependencies in either direction, including "extends" and "implements".

In terms of Maven project structure, the best way to do so is to use joint compilation. That is, instead of having Java sources in "src/main/java" and Groovy sources in "src/main/groovy", you would put both kinds of sources in a single source folder. This way you can take existing Java sources and convert them to Groovy without having to move them to a different location (and you could convert Groovy sources to Java as well, if you have reason to do so).

There are examples of basic project structures that use the joint compilation model here: https://github.com/groovy/groovy-eclipse/tree/master/extras/groovy-eclipse-compiler-tests/src/it

"basic-mixed" gives you joint compilation. "basic-standard" will give you a canonical maven separation of source types. Note: You can ignore verify.bsh as it is part of the integration test, not part of the project structure.

There is more discussion of these details here: https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM