How to run a JPA application using JShell

João Antonio Ferreira joao.parana at gmail.com
Fri Jan 1 17:31:12 UTC 2016


Sure !

Install Docker then run this commands:

The *dockerhost.local* host is *boot2docker* or *docker-machine* host on
MAC OS X or Windows. On Linux you can use 127.0.0.1

docker pull parana/jshell

export MYSQL_ROOT_PASSWORD=xpto
docker run -d --name mysql_db -p 3306:3306 \
       -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD \
       -e MYSQL_DATABASE=test \
       -e MYSQL_USER=test \
       -e MYSQL_PASSWORD=test \
       mariadb bash

# Verify MySQL database connection
mysql -u root -h *dockerhost.local* -p # Please provide the password xpto
mysql> show databases;
mysql> use test;
mysql> show tables;


Running JPA test with JShell on Docker container

docker run -i -t --rm --name jshell \
       --link mysql_db:mysql \
       parana/jshell bash

# Verifying persistence.xml
jar -tvf target/myJshellAppLib.jar META-INF/persistence.xml
# Testing  JAR App inside console. This run OK !
java -jar target/myJshellAppLib.jar

# Testing inside Shell. This throw an javax.persistence.PersistenceException

jshell
/classpath target/myJshellAppLib.jar
import br.com.joaoparana.*
App app = new App()
String[] args = {}
App.main(args)

Starting JPA Test with MySql Database

|  javax.persistence.PersistenceException thrown: *No Persistence provider
for EntityManager named myPersistence*

|        at Persistence.createEntityManagerFactory (Persistence.java:85)

|        at App.getEMF (App.java:100)

|        at App.main (App.java:37)

|        at (#12:1)

This simple project can be viewed on
https://github.com/joao-parana/jshell/tree/master/my-jshell-app

This sound like a Classloader problem.

I hope this help.

João Antonio
​



2015-12-30 9:44 GMT-02:00 Ben Evans <benjamin.john.evans at gmail.com>:

> Hi Joao,
>
> Could you post a minimal test case that demonstrates the problem?
>
> Thanks,
>
> Ben
>
> On Wed, Dec 30, 2015 at 11:36 AM, João Antonio Ferreira
> <joao.parana at gmail.com> wrote:
> > I'm unable to load the persistence.xml file when using a Shell JPA
> > application.
> >
> >
> > João Antonio
>


More information about the kulla-dev mailing list