52

Is there a CRUD generator utility in Java like Scaffolding in Rails? Can be in any framework or even plain servlets. Must generate controllers + views in jsp, not just DAO code...

Sathish
  • 20,660
  • 24
  • 63
  • 71

22 Answers22

28

Spring Roo seems to be exactly what you're looking for: CRUD code generation, spits out pure Java code that can be made tun run entirely independant from the framework.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • 1
    Well, not quite pure Java, there a whole lot of AspectJ in there by default, and I've heard varying reports as to how completely it can be removed without some elbow grease being applied. – mezmo Jan 21 '11 at 16:28
  • But I thougth AspectJ were Java. – John John Pichler Jul 22 '11 at 19:28
  • 1
    @Ed: It's basically an extension of Java that adds new language constructs. It requires a special compiler (that is generally slower than the regular Java compiler) as well as (I think) a runtime component. – Michael Borgwardt Jul 22 '11 at 19:38
16

Grails has scaffolding.

Hates_
  • 66,613
  • 6
  • 32
  • 37
  • 4
    +1. but note, grails is actually based on Groovy - but groovy is backwards compatible with java and you can mix and match groovy and java classes in the same project. – frankodwyer Jan 05 '09 at 21:45
  • Also note that JRuby and Rails works acceptably on the JVM as well. – Bill K Jan 05 '09 at 23:06
  • 3
    sorry for the downvote, but I think the question specified Java, not JVM – Bozho Jan 08 '10 at 10:11
  • 1
    @Bozho: and "Java" can only ever mea "Java, the language" and is never used as "Java, the platform"? – Joachim Sauer Jan 08 '10 at 10:13
  • you are right in general. But in case of such ambiguity it is proper to first ask the OP what he really means. Otherwise the more straightforward (i.e. Java-the-language) is assumed. Imo :) – Bozho Jan 08 '10 at 10:18
14

See the Telosys Tools Eclipse plugin at http://www.telosys.org/

The plugin connects to the database, generates a lightweight repository, lets you customize the repository if necessary and generates Java Beans, DAO, XML converters, ScreenMaps (JSP) etc...

You can build a Data Centric Web App in few minutes

J Thomson
  • 141
  • 1
  • 2
  • 1
    Tutorials are available here : https://sites.google.com/site/telosystutorial/ for Spring MVC, Spring Data, JPA, AngularJS, etc – John T Apr 10 '14 at 09:20
  • Telosys is my preferred code generator because it is free, open source, light, handy and moreover it generates clean Java code. As all the templates are customizable you can generate exactly what you want. – rlopez Dec 01 '20 at 18:16
10

Use JHipster. It is built on the popular front end scaffolding tool 'yeoman'. It not only generates your back end including controllers, dao, security, user management, system and API metrics, logging etc using Spring Boot & Spring MVC 4, but also generates your front end using angular js. You also get goodies like grunt, karma and bower fully setup and ready to use! Along with this you also get database versioning!

It also has sub generators for generating domain entities which generates your java and corresponding front end for managing it's data.

It takes 10 mins to get a full webapp running.

Varun Achar
  • 14,781
  • 7
  • 57
  • 74
  • 3
    JHipster is good but it generates a lot for you, much of it is tons of boilerplate you might not even need and making modifications to the generated code is not exactly trivial. If you want to use Spring Boot you are better off writing your application from scratch which is really easy with the starters and use Spring Data REST + Angular-HATEOAS + yeoman. In my opinion it's useful to see how a couple of technologies should work together. – Cenobyte321 Sep 09 '15 at 21:22
  • Yes.. JHipster does provide a lot of boilerplate code, some of it is useful like the security, logging, metrics, angularjs setup, grunt setup etc.. Some of the code like the admin html pages etc aren't since you'll almost always change the UI, but the JS code is still useful. Overall, it's a good way to start working quickly without having to waste time in setup. I'd still go for it. – Varun Achar Sep 12 '15 at 04:36
  • BTW, the newer version of JHipster is splitting stuff into modules so you can only use what you need. This will fix the issue you raised. – Varun Achar Sep 12 '15 at 04:37
  • 1
    As an alternative https://bootify.io may be interesting when you need just plain Spring Boot code. – Thomas Mar 23 '21 at 15:20
8

JBoss Seam has a scripting utility called seam-gen that will create scaffolding:

http://docs.jboss.org/seam/1.1BETA2/reference/en/html/gettingstarted.html

Matt Sidesinger
  • 2,124
  • 1
  • 22
  • 18
6

AppFuse.

It is very powerful, perhaps it will be too powerful for the task in question, but it does it well.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
6

I came across this question and tried many suggested answers. In the end, I found Lightadmin. It does not generate CRUD code, but provides a nice front end to Entity classes with very little code. To make the User entity available through the Lightadmin web interface, it only needs two changes in the XML files and then a UserAdministration class:

public class UserAdministration extends AdministrationConfiguration<User> {
    /* empty */
}

You can configure the field names (and probably much more) in this Administration class, but I find it already very useful without any further configuration. The Getting Started guide really shows how easy it is. After these simple steps you can open the admin interface over http://localhost:8080/TestApp/admin.

Benedikt Köppel
  • 4,853
  • 4
  • 32
  • 42
5

It might be a bit out of context, but for Java EE, there is Jboss Forge. There is an example that uses it.

jacktrades
  • 7,224
  • 13
  • 56
  • 83
5

Netbeans has something like this.

There's a demo here: http://www.netbeans.org/kb/55/persistence-demo.html

Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
5

There's krank on Google Code. I haven't tried it yet, but it looks promising.

Adam Jaskiewicz
  • 10,934
  • 3
  • 34
  • 37
4

Have a look at Minuteproject

And try it's demos.

Regarding technologies

If you look for just ORM + DAO try the track BSLA-JPA2 (BSLA meaning Basic Spring Layer Architecture). It promotes mask pattern to ease search.

If you want Active record oriented persistence look at JOOQ or Roo

If you want servlets look at minuteproject 4 Openxava or 4 Primefaces

If you want portlets look at Liferay Service builder minuteproject will generate service.xml input from your DB.

Regarding your model

If you want that your code (java) follows java convention and not DB convention use minuteproject. It has enrichment facilities that allows to:

  • Package entities (table/view)
  • Apply entity/field naming conventions
  • Apply stereotypes/constraints/validations
  • retrieve relationships (one2many, many2one, many2many) if foreign keys are missing ex here
  • And many more

This enrichment can be applied individually at field/entity/package or globally via conventions (So you configure your own conventions).

xflorian
  • 367
  • 2
  • 5
4

Have a look at tools like:

MetaWidget http://www.metawidget.org/

ISIS http://incubator.apache.org/isis/index.html (previously Naked Objects)

They generate UI's "on-the-fly" but allow you to customise the UI when necessary.

Much better than code generation.

Noel Grandin
  • 3,143
  • 25
  • 17
3

Since the question was asked, there are several frameworks for Java that came out. Check out Spring Roo, and Play Framework. There is also Skyway Builder, which I think predates both.

Jean Barmash
  • 4,788
  • 1
  • 32
  • 40
3

Check out Tynamo

Kalle
  • 2,157
  • 1
  • 22
  • 21
3

NetBeans can generate CRUD for existing database in JSF.

What about OpenXava http://openxava.org ?

Andrey
  • 31
  • 1
2

Try Grails at http://www.grails.org/

Azizasm
  • 21
  • 1
2

give a try to generjee

It generates CRUD and provides you backend along with frontend using specs like JPA, EJB, JSF framework using primefaces, java security, authentication, auditing, excel and pdf exporting, user management, user registration.

Afterward you can download the source code or deploy to heroku. I've tested it and it gave me expected results

daniel rubambura
  • 545
  • 6
  • 12
2

See Jspresso - http://www.jspresso.org/
It features multiple front-ends (Flex, pure HTML/Javascript, Swing, etc) but it does not give you much freedom on the view part. It's worth checking though.

2

Do not forget Play. Extramely easy to use. Once you have experience in ruby on rails it will be easy for you to adapt in Java too..

takacsot
  • 1,727
  • 2
  • 19
  • 30
1

I've got this a long time ago.

http://mahosoft.com/docs/WhitePaper-WEB-App-Spanish.pdf

Google translation to english:

http://translate.google.com/translate?hl=en&u=http://mahosoft.com/docs/WhitePaper-WEB-App-Spanish.pdf&sl=es&tl=en

May be outdated though.

OscarRyz
  • 196,001
  • 113
  • 385
  • 569
1

reinCRUD is a vaadin add-on which works using annotated hibernate entities. You can create a CRUD application within a few minutes and you can re-use components like lists, forms and search forms.

Florian
  • 3,069
  • 1
  • 26
  • 26
0

If you have an example project containing the kind of CRUD (or whatever) architecture you want, then Simple Scaffolding might be a useful approach.

It's a single class that scans your existing code base and creates templates which you can then apply to other entities. For example, MongoUserDao can be turned into a template which then generates, say, MongoCustomerDao. It works with any code and test fixtures.

Very basic, but gets the job done and it's FOSS under MIT license.

The GitHub repo is here: https://github.com/gary-rowe/SimpleScaffolding

Gary
  • 7,167
  • 3
  • 38
  • 57