Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8154374

JShell: setContextClassLoader() for remote Snippet class loader

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 9
    • tools
    • b133
    • generic
    • generic
    • Verified

      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

      I was able to reproduce. The problem seems to be that javax.persistence.Persistence is using Thread.getContextClassLoader() to lookup PersistenceProviders, but the context CL is not set to the REPL CL in RemoteAgent. Robert, is there a reason why we couldn't do:
      Thread.currentThread().setContextClassLoader(loader);
      ?

      It would make sense to me to set this.

      Thanks,
         Jan

            rfield Robert Field (Inactive)
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: