Monday, May 11, 2020

Java app code generators

What I'm trying to do

Clear back in 2005 I wrote my first app to get CRUD pages for a web app from a quick look a the DB metadata. I've done it again  many times since. Always with an eye to making my task easier instead of a generic app. Every time I first look to see if anyone has done somehting similar for the framework I'm using for that project but it always turns out the be easier to just write something myself than the tools I found. Since I've been doing a lot of stuff with containers lately I though it would be good to be able to quickly spin up POC apps for project demos so I'm looking at generators again.

For this POC I started with a simple SQLite DB with just 2 tables. Shows and Networks.

Options tried

The Eclipse market place just lists a couple and I heard about others. Really only Telosys in the market place seemed to be used by more than a few people.

Spring Initializr

Creates a basic project template but need classes created. There are lots of Spring Boot classes on Lynda.com though and it does give you a projects with most of the dependencies you might need.

Telosys

The plugin seems have a lot of downloads and the screen shots look promising but there appears to be no documentation at all. I messed with a bit but

JMR

It is from a Chinese developer and only downloaded 39 times so that is probably a deal breaker right there. On the other hand it at least has documentation to get you started. But it seems to be mainly a GUI for creating JSP style templates to gen code from so again not sure how much of a time saver it would be.

New JPA project

My first issue was I was using  Spring Tools 4.3 from a previous project and creating a JPA project was not even an option.

From the Eclipse Oxygen I tried it just hung creating the project. After about 30 minutes or so it FINALLY unstuck. I generated the beans  per the instructions and got something close. That step went pretty fast but for the overhead I do not see it as worth it for just a few tables.

While I was waiting to see if Oxygen would ever return I downloaded the latest Spring Tools 4.6. But again creating a JPA project is not a option. (Granted I could keep installing tools till I got something to work or it stopped working but the point was to find something simpler than just writing my own code.)

In the end it seems to do "OK" if you do not have (or at least tell it you have) association between tables. Even then though you need to tell it what class to use for every field or it makes them all Objects. It also seems to fail if you do not tell it the id field. So still probably as much trouble to config as to just create the POJOs by hand.

g9 Database Import

Another POJO generator. Does not support SQLite though.

Speedment

To start you use their initializer instead of the Spring Boot one.

It wants Maven 3.5.3 (release Feb 2018) or better to run so that meant a newer IDE.
Note the newer Eclipse zips seem to have an error in them which means you need to manually edit the config.ini or use the installer.

After installing and running the generate tool on the 2 tables with defaults settings I had 91 files generated. I had to "disable" some other tables left over from importing the sheets into the DB. That left me with 46 files for the 2 tables. Note rerunning the tools removes the files for the "disabled" tables. Unfortunately the rest interface it generates appears to be broken and just gives you 404s.

JHipster

The one class there was for it on Lynda.com can not be accessed via LinkedIn Learning. Not sure what is going on there but does not bode well. I wanted to look at it first but was turned off this. But after trying the above I decided to give it a try.
I followed these instructions for setup. Note when running the generator the docs are a bit out of step with what is on screen starting at step 13.
Note I was missing several things it needed and had to run
npm install rimraf -g
npm install webpack (note the missing -g as it expects it to be below the app folder)
npm install write-file-webpack-plugin
npm install webpack-merge
npm install browser-sync-webpack-plugin
npm install browser-sync
npm install webpack-notifier
npm install xml2js
npm install copy-webpack-plugin
npm install html-webpack-plugin
npm install rxjs
npm install merge-jsons-webpack-plugin
then run jhipster again. Fortunately it remembered where it errored out each time.
After all that the java code did not build
ERROR in Entry module not found: Error: Can't resolve 'angular2-template-loader' in 'D:\eclipse-jee-2020-03\workspace\BugTrackerJHipster'

ERROR in Entry module not found: Error: Can't resolve 'angular2-template-loader' in 'D:\eclipse-jee-2020-03\workspace\BugTrackerJHipster'

ERROR in Entry module not found: Error: Can't resolve 'style-loader' in 'D:\eclipse-jee-2020-03\workspace\BugTrackerJHipster'

ERROR in   Error: Child compilation failed:
  Entry module not found: Error: Can't resolve 'html-loader' in 'D:\eclipse-jee-2020-03\workspace\BugTrackerJHipster':
  Error: Can't resolve 'html-loader' in 'D:\eclipse-jee-2020-03\workspace\BugTrackerJHipster'

  - compiler.js:76
    [BugTrackerJHipster]/[html-webpack-plugin]/lib/compiler.js:76:16

  - Compiler.js:300 compile
    [BugTrackerJHipster]/[webpack]/lib/Compiler.js:300:11

  - Compiler.js:510 applyPluginsAsync.err
    [BugTrackerJHipster]/[webpack]/lib/Compiler.js:510:14

  - Tapable.js:202 next
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:202:11

  - CachePlugin.js:78 Compiler.<anonymous>
    [BugTrackerJHipster]/[webpack]/lib/CachePlugin.js:78:5

  - Tapable.js:206 Compiler.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:206:13

  - Compiler.js:507 compilation.seal.err
    [BugTrackerJHipster]/[webpack]/lib/Compiler.js:507:11

  - Tapable.js:195 Compilation.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:195:46

  - Compilation.js:680 self.applyPluginsAsync.err
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:680:19

  - Tapable.js:195 Compilation.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:195:46

  - Compilation.js:671 self.applyPluginsAsync.err
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:671:11

  - Tapable.js:195 Compilation.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:195:46

  - Compilation.js:666 self.applyPluginsAsync.err
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:666:10

  - Tapable.js:195 Compilation.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:195:46

  - Compilation.js:662 sealPart2
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:662:9

  - Tapable.js:195 Compilation.applyPluginsAsyncSeries
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:195:46

  - Compilation.js:605 Compilation.seal
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:605:8

  - Compiler.js:504 applyPluginsParallel.err
    [BugTrackerJHipster]/[webpack]/lib/Compiler.js:504:17

  - Tapable.js:289
    [BugTrackerJHipster]/[tapable]/lib/Tapable.js:289:11

  - Compilation.js:507 _addModuleChain
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:507:11

  - Compilation.js:390 errorAndCallback.bail
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:390:4

  - Compilation.js:413 moduleFactory.create
    [BugTrackerJHipster]/[webpack]/lib/Compilation.js:413:13

  - NormalModuleFactory.js:235 factory
    [BugTrackerJHipster]/[webpack]/lib/NormalModuleFactory.js:235:20

  - NormalModuleFactory.js:60 resolver
    [BugTrackerJHipster]/[webpack]/lib/NormalModuleFactory.js:60:20

  - NormalModuleFactory.js:191 asyncLib.parallel
    [BugTrackerJHipster]/[webpack]/lib/NormalModuleFactory.js:191:21

  - async.js:3888
    [BugTrackerJHipster]/[async]/dist/async.js:3888:9

  - async.js:473
    [BugTrackerJHipster]/[async]/dist/async.js:473:16

  - async.js:1062 iteratorCallback
    [BugTrackerJHipster]/[async]/dist/async.js:1062:13

  - async.js:969
    [BugTrackerJHipster]/[async]/dist/async.js:969:16

  - async.js:3885
    [BugTrackerJHipster]/[async]/dist/async.js:3885:13


error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
If you find JHipster useful consider supporting our collective https://opencollective.com/generator-jhipster

Server application generated successfully.

Run your Spring Boot application:
 ./mvnw (mvnw if using Windows Command Prompt)
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: ERROR! webpack:build failed.
    at Environment.error (C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\generator-jhipster\node_modules\yeoman-environment\lib\environment.js:157:40)
    at module.exports.error (C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\generator-jhipster\generators\generator-base.js:2064:18)
    at module.exports.end (C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\generator-jhipster\generators\client\index.js:410:18)
    at Object.<anonymous> (C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\yeoman-generator\lib\index.js:399:25)
    at C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\run-async\index.js:25:25
    at new Promise (<anonymous>)
    at C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\run-async\index.js:24:19
    at self.env.runLoop.add.completed (C:\Users\avata\AppData\Local\Yarn\Data\global\node_modules\yeoman-generator\lib\index.js:400:11)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)



1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete