2016/02/07 - Apache Onami has been retired.

For more information, please explore the Attic.

Standalone Application

java code

public static void main( String[] args )
{

    final PersistenceModule persistenceModule = new PersistenceModule()
    {

        @Override
        protected void configurePersistence()
        {
            bindApplicationManagedPersistenceUnit( "puName" );
        }

    };

    final Injector injector = Guice.createInjector( persistenceModule, getApplicationSpecificModules() );

    final PersistenceService persistenceService = injector.getInstance( PersistenceService.class );

    try
    {
        persistenceService.start();

        while( notTerminated() )
        {
            // run application
        }
    }
    finally
    {
        persistenceService.stop();
    }
}

persistence.xml

<persistence
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="puName" transaction-type="RESOURCE_LOCAL">
        <!-- your configuration -->
    </peristence-unit>

</peristence>

Structure of the .jar

+ app.jar
|    + META-INF
|    |    + MANIFEST.MF
|    |    + persistence.xml
|    + foo
|    |    + bar
|    |    |    + Main.class
|    |    |    + App.class