jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

eclipse plugin to auto generate java classes from json

Open raviproperty opened this issue 6 years ago • 6 comments

Hi i am using jsonschema2pojo-maven-plugin 1.0.1 plugin in eclipse to generate sources. but my problem is that it does not auto generate classes i need to run mvn package to do so. is there a way by which i can auto generate java classes whenever there is a change in .json files?? like how the java compiler plugin works?

raviproperty avatar Oct 04 '19 09:10 raviproperty

Someone could write a plugin for eclipse using jsonschema2-pojo core but there might be a way to execute a pre-build step in you eclipse project. You could try to execute just the json2schema-mojo goal.

Sorry it's been awhile since I have used eclipse but I thought there was something a maven plugin could do to be more friendly for eclipse.

ddcruver avatar Nov 01 '19 02:11 ddcruver

@raviproperty This is how someone may be able to do it if they want to implement it for this plugin. https://www.eclipse.org/m2e/documentation/m2e-making-maven-plugins-compat.html

ddcruver avatar Nov 01 '19 03:11 ddcruver

For java code generating mojos, failure to act on relevant input changes only will almost certainly result in endless build – mojo generates .java files, which triggers jdt to generate .class files, which triggers the mojo to generate .java files, and so on.

This is an excerpt from their wiki so for the case of the plugin type it may not be as trivial as just adding the lifecycle mapping.

ddcruver avatar Nov 01 '19 03:11 ddcruver

At one time, this plugin did work with m2e to generate sources as part of Eclipse's incremental build. You can see our configuration here:

https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml

I'm not sure why this is not working for @raviproperty. If be interested to know if this affects anyone else.

joelittlejohn avatar Nov 01 '19 07:11 joelittlejohn

So @joelittlejohn you mean if I just change <runOnIncremental>true</runOnIncremental> in plugin it will work? but then if we have to override this in my project pom.xml, how can i do it please? also if there are 20+ json files in my project would it slow down the generation of java code by enabling this option?

raviproperty avatar Nov 01 '19 10:11 raviproperty

I could use more information about this. The reference to "runOnIncremental" is not in the plugin configuration, but in the lifecycleMappingMetadata, but I'm not certain exactly what to do here. The "lifecycle-mapping-metadata.xml" file referred to in that link doesn't look exactly like the the same file in my Eclipse. I can see how to interpolate the differences, as it appears I need to add "groupId", "artifactId", and "versionRange" properties corresponding to the jsonschema2pojo plugin, but I also note that the file linked to in the project here has "runIncremental" set to FALSE, not true, so I'm additionally confused here. In any case, I tried setting it to both false and true, but nothing magically generated the source. I also tried doing "update project" and "project clean". Nothing worked.

davidmichaelkarr avatar Mar 19 '21 18:03 davidmichaelkarr