1

is it possible to write a "maven plugin" or something like that which changes the .java at compile time?

For example:

@Entity
... class ... {
  @Id
  long id
}

I would like to comment out all the Annotations and Create a ORM-Mapping.xml / Persistence according to the entitys

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
pro sp
  • 53
  • 5

3 Answers3

0

The annotations are mostly based on the configuration files which enable/disable their recognition.

Use the Spring profiles to distinguish the configuration classes. If the special profile will appear, no configuration classes will be recognized. The solution requires to make all the configurations configurable according to the Spring profiles.

@Configuration
@Profile("noAnnotations")
public class SomeConfigurationClass
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
0

It's possible. Project lombok modifies compiled code however there's no exposed API to do that. (See How does lombok work?) Which is what you want if you have to strip annotations. Disabling all annotations at runtime is probably not reasonable. If you just want to generate something from annotations found in compiled classes that is much simpler

Lev Kuznetsov
  • 3,520
  • 5
  • 20
  • 33
-1

What you describe sounds like you're looking for something like a C/C++ preprocessor/templating - feature?

Maybe Annotation Processing can help you https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html

Apart from that - inferring a persistence.xml from your entities annotations is something the Spring Framework does.

Nigel Nop
  • 180
  • 1
  • 6