| Subcribe via RSS or via Email

A ‘LegUp’ for new Java projects

October 7th, 2009 Posted in Java

Nowadays, even a simple Java web system is going to require a web framework, some sort of persistence layer and probably some sort of dependency injection.  But how long would it take you to create such a project from scratch?  1 day? 1 hour maybe if you knew all of the technologies involved.  With LegUp you can be up and running in 15 seconds*.

LegUp is a collection of free, open source (Apache 2 licensed) Maven 2 archetypes, and a web based configuration tool provided by jWeekend.  It allows you to choose from different combinations of popular Java technologies (Apache Wicket, Spring, Google Guice, JPA, Hibernate, Warp Persist) to allow you to get up and running quickly and easily.  Up and running means that will have a simple application running within a minute of starting.

Currently the following archetypes are available:

  • Spring 2.5 with a JDBC database layer
  • Spring 2.5 with a JPA 1.0 database layer
  • Apache Wicket 1.4 and Google Guice 1.0
  • Apache Wicket 1.4, Google Guice 1.0, Warp Persist 1.0 and Hibernate 3
  • Apache Wicket 1.4, Google Guice 1.0, Warp Persist 1.0 and JPA 1.0
  • Apache Wicket 1.4, Spring 2.5 and JPA 1.0
The projects using JPA include multiple JPA providers.  Hibernate is the default, but both OpenJPA and EclipseLink are also included.  To change the provider, comment out the hibernate dependency in the projects pom.xml and uncomment the desired provider.  Then comment out/in the appropriate lines in the persistence.xml file.

Example for a project with Wicket, Spring and JPA

  • Make sure you have Java 5+ and Maven 2 installed and working.  You can search on the internet for how to do this if you are not sure.
  • Go to the LegUp configuration page in your web browser of choice.
  • Select the Wicket, Spring, JPA archetype from the drop down list.
  • Optionally customize the Group Id, Archetype Id, Version and Package fields.  These are standard Maven properties.  I will leave the defaults for this example.
  • Click the ‘Generate Maven Command’ button.  This will populate the text area under the button.
  • Open a terminal window (Mac, Linux) or command prompt window (Win) and cd to a suitable directory.
  • Copy the command line (starts with mvn archetype:generate) and paste it into your open terminal.
  • Hit enter and wait for maven to finish processing the command.  The time this will take depends on the speed of your internet connection and how populated your local maven repository is.  It could take a few minutes if this is the first time you have used maven.
  • Cd into the directory which has been produced, this will be named the same as the Archetype Id you entered earlier.  In my case this directory is called ‘myproject’.
    cd myproject
  • Build the application and run the provided tests using this maven command:
    mvn compile test
  • Run the wicket application on jetty with this maven command.
    mvn jetty:run
  • Thats it, you now have a running Wicket Application with Spring Dependency injection and JPA using hibernate under the covers, all running with a HSQL database.

Added bonus feature

If you type the following maven command, it will generate you an eclipse project which you can import into eclipse to start editing the code straight away

mvn eclipse:eclipse

Gotchas

  • Warp Persist will need installing into your local repository manually.  Download it from the Warp Persist website and follow the instructions that maven gives you.
*15 seconds is assuming that your maven repository contains all of the required jars already.
** Disclaimer, I work for jWeekend.

9 Responses to “A ‘LegUp’ for new Java projects”

  1. Dave Says:

    I tried to generate a project, and got the following error:

    $ mvn archetype:generate -B -DarchetypeCatalog=http://legup.googlecode.com/svn
    /repo/archetype-catalog.xml -DarchetypeArtifactId=wicket-spring-jpa-archetype -
    DarchetypeGroupId=com.jweekend -DarchetypeVersion=0.8.0 -DgroupId=com.mycompany -
    DartifactId=myproject -Dversion=1.0-SNAPSHOT -Dpackage=com.mycompany
    [INFO] Scanning for projects…
    [INFO] Searching repository for plugin with prefix: ‘archetype’.
    [INFO] ————————————————————————
    [INFO] Building Maven Default Project
    [INFO] task-segment: [archetype:generate] (aggregator-style)
    [INFO] ————————————————————————
    [INFO] Preparing archetype:generate
    [INFO] No goals needed for project - skipping
    [INFO] Setting property: classpath.resource.loader.class => ‘org.codehaus.plexus
    .velocity.ContextClassLoaderResourceLoader’.
    [INFO] Setting property: velocimacro.messages.on => ‘false’.
    [INFO] Setting property: resource.loader => ‘classpath’.
    [INFO] Setting property: resource.manager.logwhenfound => ‘false’.
    [INFO] [archetype:generate {execution: default-cli}]
    [INFO] Generating project in Batch mode
    [WARNING] Error reading archetype catalog http://legup.googlecode.com/svn/repo/a
    rchetype-catalog.xml
    org.apache.maven.wagon.ResourceDoesNotExistException: Unable to locate resource
    in repository
    at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputD
    ata(LightweightHttpWagon.java:139)
    at org.apache.maven.wagon.StreamWagon.getInputStream(StreamWagon.java:11
    6)
    at org.apache.maven.wagon.StreamWagon.getIfNewer(StreamWagon.java:88)
    at org.apache.maven.wagon.StreamWagon.get(StreamWagon.java:61)
    at org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource.ge
    tArchetypeCatalog(RemoteCatalogArchetypeDataSource.java:74)
    at org.apache.maven.archetype.DefaultArchetype.getRemoteCatalog(DefaultA
    rchetype.java:203)
    at org.apache.maven.archetype.ui.DefaultArchetypeSelector.getArchetypesB
    yCatalog(DefaultArchetypeSelector.java:249)
    at org.apache.maven.archetype.ui.DefaultArchetypeSelector.selectArchetyp
    e(DefaultArchetypeSelector.java:74)
    at org.apache.maven.archetype.mojos.CreateProjectFromArchetypeMojo.execu
    te(CreateProjectFromArchetypeMojo.java:180)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
    nManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
    ultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
    Goal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
    ltLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
    dleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
    ts(DefaultLifecycleExecutor.java:284)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
    fecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
    0)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: java.io.FileNotFoundException: http://legup.googlecode.com/svn/repo/a
    rchetype-catalog.xml/archetype-catalog.xml
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.j
    ava:1298)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpU
    RLConnection.java:1292)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:948)
    at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputD
    ata(LightweightHttpWagon.java:122)
    … 27 more
    Caused by: java.io.FileNotFoundException: http://legup.googlecode.com/svn/repo/a
    rchetype-catalog.xml/archetype-catalog.xml
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:1243)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373
    )
    at org.apache.maven.wagon.providers.http.LightweightHttpWagon.fillInputD
    ata(LightweightHttpWagon.java:115)
    … 27 more
    [INFO] ————————————————————————
    [ERROR] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] : java.lang.NullPointerException

    [INFO] ————————————————————————
    [INFO] For more information, run Maven with the -e switch
    [INFO] ————————————————————————
    [INFO] Total time: 7 seconds
    [INFO] Finished at: Fri Oct 09 13:11:16 MDT 2009
    [INFO] Final Memory: 8M/15M
    [INFO] ————————————————————————
    $


  2. Richard Says:

    I just ran the same command and it worked fine, what version of maven are you using?

    Can you try changing this bit of the command line:
    -DarchetypeCatalog=http://legup.googlecode.com/svn/repo/archetype-catalog.xml

    to this:
    -DarchetypeCatalog=http://legup.googlecode.com/svn/repo

    and let me know if it works.


  3. Paul Says:

    Brilliant idea!
    I saved many boring hours after I read your nice article and took the simple Leg Up! Thanks so much, it could not be more easy. Because maven is new for me but getting started is easy like this.

    But no glass-fish & wicket? jboss? jeronimo? jee 5 is not bad such Wicket guy thinks (ok, j2ee is quite horrible) and jee app server world could enjoy to have quick, easy experiment of Wicket for web tier, and, maybe reverse also for a Wicket guy :-)

    @Dave - I did make project for spring, jpa and also wicket, spring from Leg Up on debian 5 and vista at office and Mac OSX at my home with Java 5 and maven 2.1.0 (what did you try?). Did you try your installed maven with other archetype (http://wicket.apache.org/quickstart). Is your .m2 folder clean - move it and and try again also. I did no try Java 6 with this but I think it will not be the problem.


  4. Cemal Says:

    Dave,

    See http://www.nabble.com/forum/ViewPost.jtp?post=25844727&framed=y

    Regards - Cemal
    jWeekend
    OO & Java Technologies, Wicket Training and Development
    http://jWeekend.com


  5. Daily del.icio.us for October 2nd through October 13th | Vinny Carpenter's blog Says:

    [...] A ‘LegUp’ for new Java projects | Richard Wilkinson’s Blog – LegUp is a collection of free, open source (Apache 2 licensed) Maven 2 archetypes, and a web based configuration tool provided by jWeekend. It allows you to choose from different combinations of popular Java technologies (Apache Wicket, Spring, Google Guice, JPA, Hibernate, Warp Persist) to allow you to get up and running quickly and easily [...]


  6. Peter Says:

    I am using the following template:
    Apache Wicket 1.4, Google Guice 1.0, Warp Persist 1.0 and JPA 1.0

    After this it works fine and I updated to
    warp persist 2.0-20090214 and google guice 2.0. I had to change the filter according to this information:

    http://www.atomicgamer.com/dev/2009/10/wicket-guice-2-0-warp-persist-2-0/

    Then I moved to db4o where I had to insert a ‘deleteAll’ in test-setup before all tests passed.

    But now if I want to run the webapp I get:

    java.lang.IllegalArgumentException: Configuration already used.
    at com.db4o.internal.Config4Impl.assertIsNotTainted(Config4Impl.java:1094)
    at com.db4o.cs.internal.config.LegacyClientServerFactoryImpl.openClient(LegacyClientServerFactoryImpl.java:24)
    at com.db4o.Db4o.openClient(Db4o.java:152)
    at com.wideplay.warp.persist.db4o.Db4oInternalWorkManager.beginWork(Db4oInternalWorkManager.java:50)
    at com.wideplay.warp.persist.db4o.Db4oInternalWorkManager.beginWork(Db4oInternalWorkManager.java:28)
    at com.wideplay.warp.persist.db4o.Db4oWorkManager.beginWork(Db4oWorkManager.java:34)
    at com.wideplay.warp.persist.PersistenceFilter$1$1.start(PersistenceFilter.java:90)
    at com.wideplay.warp.persist.internal.Lifecycles.failEarly(Lifecycles.java:39)
    at com.wideplay.warp.persist.internal.Lifecycles.failEarlyAndLeaveNoOneBehind(Lifecycles.java:27)
    at com.wideplay.warp.persist.PersistenceFilter.doFilter(PersistenceFilter.java:155)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1148)

    Do you have any suggestions?

    Here is the guice setup snippet, called in Module.configure():

    install(PersistenceService.usingDb4o().across(UnitOfWork.REQUEST).
    forAll(Matchers.any(), Matchers.annotatedWith(Transactional.class)).buildModule());

    bind(EventDao.class).to(EventDaoDb4o.class);

    Configuration config = Db4o.newConfiguration();
    bind(Configuration.class).toInstance(config);

    bindConstant().annotatedWith(Names.named(Db4Objects.HOST)).to(Db4oServer.HOST);
    bindConstant().annotatedWith(Names.named(Db4Objects.PORT)).to(Db4oServer.PORT);
    bindConstant().annotatedWith(Names.named(Db4Objects.USER)).to(Db4oServer.USER);
    bindConstant().annotatedWith(Names.named(Db4Objects.PASSWORD)).to(Db4oServer.PASSWORD);


  7. Peter Says:

    forgot to say that this test project is available here:

    https://timefinder.svn.sourceforge.net/svnroot/timefinder/branches/timefinderwicket

    You will need to start the db4o server via Db4oServer before executing tests or the webapp.

    The warp persist 2.0-20090214 project is located here:

    http://warp-persist.googlecode.com/svn/tags/20090214/warp-persist/dist/warp-persist-2.0-20090214.zip


  8. Richard Says:

    Hi Peter,

    Sorry I don’t have any experience with db4o. The only thing I can think is that the warp page on the db40 module (http://www.wideplay.com/webextensions%3A%3Ajpaintegration22) does seem to not show :

    Configuration config = Db4o.newConfiguration();
    bind(Configuration.class).toInstance(config);

    Thanks,

    Richard


  9. Peter Says:

    ok, thanks + no problem… without that line he says:
    “Must specify a Configuration when using localhost server mode. For starters, try: bind(Configuration.class).toInstance(Db4o.newConfiguration());”

    :-)


Leave a Reply

retaggr