From suggestions in this thread of placing EntityManagerFactory in the main
class, I figured that I needed to step back and learn more about that
suggestion.
I took my application (happens to be KART) and placed the following into
Main.java (main class provided by Netbeans):
@PersistenceUnit(unitName="SVG_drawings")
private static EntityManagerFactory emf;
this does NOT work!!! emf is NULL (this info must be referenced with
persistence.xml that I provided in this thread).
i replaced the two lines above with:
private static EntityManagerFactory emf;
later in code in main class (could have all been on one line):
emf = Persistence.createEntityManagerFactory("SVG_drawings");
this WORKS!!!
more lessons learned:
I could run the KART app within Netbeans but not at the command line.
In Netbeans, I right clicked on Main and selected Run File - the project
would run as stated above. See Note A below.
At the command line, I typed the following:
java -jar /usr/local/provision/KART/dist/KART.jar
this always blew an error saying:
Internal Exception: SQL Exception: Failed to start database 'derbyDB' ...
I agonized for hours. Finally, I typed
java -Dderby.system.home=/usr/local/dbHome -jar
/usr/local/provision/KART/dist/KART.jar
TADA!!!! it runs.
Next, I deploy KART to Glassfish. Then, at the command line, I type:
/usr/local/glassfish/glassfish/bin/appclient -client
/usr/local/glassfish/glassfish/domains/domain1/generated/xml/j2ee-modules/KA
RT/KARTClient.jar
it throws the error:
ValidationException.currentLoaderNotValid(ValidationException.java:1865)
Question: Is there a command line parameter to pass to appclient similar to
the '-Dderby.system.home' for the java command line and the
'?prop=DBHome=/usr/local/dbHome' for the browser URL for appclient/JWS ?
Note A: Even though the application ran from within Netbeans, it was still
not pointing to the directory that I wanted.
Note B: It is NOT necessary to place the EntityManagerFactory lines in the
main class. I have tested and the line work equally well in any class of
the project.