• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 551
  • Last Modified:

Setting up Embedded Java DB System Directory?

My application runs perfectly under Netbeans but when I build it and launch the jar file it comes up with Java Virtual Machine Launcher "A Java Exception has occured" pop-up.  I ran the java -myjar.jar and it just says a fatal error has occured.  I presume that it can't create my database at main and that's why it's coming up with this error.  I have implemented the Embedded Java DB system and and in order to set the database to be created, I have performed the following routine of code,
            
    String userHomeDir = System.getProperty("user.home");
    String systemDir = userHomeDir + "\\LMB\\";

    // Set the db system directory.
    System.setProperty("derby.system.home", systemDir);
           
    conn = DriverManager.getConnection("jdbc:derby:LMB; create=true;");

Open in new window


Do you think this is right or I'm missing something??!
0
snajalm
Asked:
snajalm
  • 20
  • 14
  • 11
  • +1
2 Solutions
 
for_yanCommented:
What is the stacktrace of your exception - please post the details
0
 
reijnemansCommented:
Do you have set your, classpath so external properties/libraries  could be found?
Could you post the error message that is displayed in your console?
0
 
for_yanCommented:

A Java Exception has occured - that can easily be about anything - before you make conculusion you should
look at the details of exception
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
snajalmAuthor Commented:
I run

java myfile.jar

Open in new window


And it only shows this error.

Error:  Could not find or load main class myfile.jar

Open in new window


I'm sure there is main method in my application class.  I don't understand what this is supposed to mean!
0
 
for_yanCommented:
Your jar poerhaps is not executable jar
0
 
for_yanCommented:
jar -jar myfile.jar

-jar is necessary
0
 
for_yanCommented:
even if jar is executable you need -jar to run it from jar

java -jar myfile.jar

try this and let us know
0
 
snajalmAuthor Commented:
C:\Documents and Settings\User\Desktop>java -jar myfile.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdesktop/applicat
ion/SingleFrameApplication
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.jdesktop.application.SingleFram
eApplication
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 13 more
0
 
for_yanCommented:
You need to have this stuff from netbeans in the classpath or on the jar
0
 
for_yanCommented:


Your application is using the Swing Application Framework. You need to include its jar in your classpath. AppFramework-1.02.jar should be in your classpath.

maybe versions is now different
0
 
reijnemansCommented:
appframework-1.0.3.jar is missing on the classpath
0
 
for_yanCommented:

you can download it form here even though you probably have it somewhere in youtr netbeans, but it  may be easier to download
http://mirrors.ibiblio.org/pub/mirrors/maven2/net/java/dev/appframework/appframework/1.03/appframework-1.03.jar
0
 
for_yanCommented:

I think you still can do it like this :

jar -cp appframework-1.03.jar -jar myfile.jar

I hope with -jar
 -cp  still should be working
0
 
snajalmAuthor Commented:
But they're all there in Netbeans as can be seen in the image provided!
untitled.bmp
0
 
reijnemansCommented:
Correct but when your making a jar other jars are not bundled into the created jar, so you have to put the libraries on the classpath yourseld
0
 
for_yanCommented:
but you are not executing it inside netbeans , you are executing it on command line - so it probably
was not packaged to jar for some reason
0
 
CEHJCommented:
I don't know how you intend to package your app but you should be able to execute with Ant without problem. Ant is already in Netbeans but you should, as a developer, install it separately too, so you have the user binaries. After setting ANT_HOME and adding %ANT_HOME%\bin to your path, you should find that the following runs your project with error
ant -f <path to build.xml of your project> run

Open in new window

0
 
snajalmAuthor Commented:
Sorry CEHJ, I didn't see this last message!  But what is an "ant" and where should I get it??!
0
 
CEHJCommented:
Ant is the primary build tool for Java.

http://ant.apache.org/bindownload.cgi

Should definitely be installed for you imo
0
 
snajalmAuthor Commented:
I installed and ran the command you proposed and everything runs smoothly outside the Netbeans environment!  However I can't find the jar fine anywhere!  What should I do from there???!
0
 
CEHJCommented:
The application jar? You'll find it's at

<project name>\dist\<project name>.jar
0
 
snajalmAuthor Commented:
I can't find it.  I noticed that it seems that it runs the application but doesn't build a jar file.  Is there any other command that would create a jar file??!
0
 
CEHJCommented:
Try the following then look again
ant -f <path to build.xml in your project> jar

Open in new window

0
 
snajalmAuthor Commented:
BUILD FAILED
C:\Documents and Settings\User\My Documents\NetBeansProjects\iDA\iDA\nbproject\b
uild-impl.xml:944: The following error occurred while executing this line:
C:\Documents and Settings\User\My Documents\NetBeansProjects\iDA\iDA\nbproject\b
uild-impl.xml:366: The <classpath> for <junit> must include junit.jar if not in
Ant's own classpath

Total time: 1 second
0
 
snajalmAuthor Commented:
When I ran the application with your initial command which included the run, my application behaved as it should have but after it's built with you latest command.  It builds successfully but does not behave the way it supposed to.  How could this possibly be???!  I'm lost here...
0
 
CEHJCommented:
http:#37000315 is the result of running the very last comment i posted?
0
 
snajalmAuthor Commented:
No, "ant -f <path to build.xml in your project> jar" runs successfully but runs with some problems whereas this same project while using the "ant -f <path to build.xml in your project> run" performs just the way it does withing Netbeans (which is the way it supposed to be).  It seems that this project has some problems with being built!


ant -f <path to build.xml in your project> without the jar and the end comes up with the Error message I showed you!
0
 
snajalmAuthor Commented:
Any ideas or suggestions???!!!
0
 
CEHJCommented:
What does the following give at the command line?
echo %ANT_HOME%

Open in new window

0
 
snajalmAuthor Commented:
%ANT_HOME%
0
 
CEHJCommented:
Then you didn't follow my earlier advice.

http:#36998588
0
 
snajalmAuthor Commented:
Sorry, I did what you said and running echo %JAVA_HOME% I get

C:\Program Files\Java\jdk1.7.0

But now that I'm trying to run ant -f buil.xml jar, it comes up with the following message,

'ant' is not recognied and an internal or external command, operable program or bacth file.

What have I done wrong here now??!
0
 
snajalmAuthor Commented:
let me tell you what I have in my environment variable list,

ANT_HOME = C:\Program Files\apache-ant-1.8.2
CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

PATH=C:\Program Files\PC Connectivity Solution\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Common Files\DivX Shared\;C:\Program Files\Common Files\Ulead Systems\MPEG;C:\Program Files\QuickTime\QTSystem\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;%ANT_HOME%\bin

Is there anything wrong here you think??!
0
 
CEHJCommented:
If http:#37000738 is what you get when you run the command i mentioned, either

a. setting the variables didn't work
b. you haven't opened a NEW command window since you set them

With any luck, b. will be the case
0
 
snajalmAuthor Commented:
Ok I fixed it now!  echo %JAVA_HOME% is pointing to the right direction and ant is launching throughout the system.  Again I have this issue of a successful build but awkward application behaviour.  The application still runs flawlessly under Netbeans itself and by using the command "ant -f build.xml run".  Can you tell me anything that could give me a logic behind where I went wrong??!  I know that I'm disturbing you but I would really appreciate it if you keep helping me out with this issue!
0
 
CEHJCommented:
>> echo %JAVA_HOME%

Glad that's working but it's not really relevant here

Please post full current error(s)
0
 
snajalmAuthor Commented:
How can I capture errors while launching the jar file from explorer??!   When I run "ant -f buid.xml run" I don't get any errors!  Is there a command that would log the errors made my running a jar file??!
0
 
CEHJCommented:
You can't run it like that - no wonder you're getting errors!
0
 
snajalmAuthor Commented:
Then how should I run it then??!   Shouldn't the jar file be able to run through the explorer??!
0
 
CEHJCommented:
A single jar has to have all its dependencies met. Other jars should be included in the manifests's classpath. Or use a 'fat jar' approach
0
 
snajalmAuthor Commented:
PLEASE let me know how these techniques work??  How can I set up a manifest file?! Isn't the manifest file generated automatically by ant or Netbeans??!  When I unzip the jar file, I can see that there is already a META-INF folder where the manifest file MANIFEST.MF exist.  I don't know this file is set up right though but please let me know how I should do it manually if I have to.  
0
 
snajalmAuthor Commented:
This is a copy of the manifest file embedded in my jar file.  It seem to have pointed to all the libraries as I check against the Netbeans listing!  Do you think this should be arranged differently??!

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0-b147 (Oracle Corporation)
Class-Path: lib/beansbinding-1.2.1.jar lib/AbsoluteLayout.jar lib/appf
 ramework-1.0.3.jar lib/swing-worker-1.1.jar lib/swing-layout-1.0.4.ja
 r lib/commons-codec-1.4.jar lib/commons-codec-1.5.jar lib/commons-log
 ging-1.1.1.jar lib/derby.jar lib/derbyLocale_cs.jar lib/derbyLocale_d
 e_DE.jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocal
 e_hu.jar lib/derbyLocale_it.jar lib/derbyLocale_ja_JP.jar lib/derbyLo
 cale_ko_KR.jar lib/derbyLocale_pl.jar lib/derbyLocale_pt_BR.jar lib/d
 erbyLocale_ru.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar
  lib/derbyclient.jar lib/derbynet.jar lib/derbyrun.jar lib/derbytools
 .jar lib/httpclient-4.1.2.jar lib/httpclient-cache-4.1.2.jar lib/http
 core-4.1.2.jar lib/httpmime-4.1.2.jar lib/jdom.jar lib/orangevolt-ant
 -tasks-1.3.8.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: ida.LMBApp
0
 
CEHJCommented:
No - that should be fine - *as long as* java is invoked from the directory containing the app jar. If you want to start it with a Windows shortcut, make sure the working directory in the shortcut properties is the one with the app jar in it
0
 
snajalmAuthor Commented:
NOTE:  
Here I FOUND THE SOURCE OF THIS ISSUE BUT I DON'T KNOW HOW TO FIX IT,

Everything about library referencing and environment variables are ok except the fact that I'm not getting my SSL connection to the server while launching the jar file whereas the connection is easily made while running the application from inside Netbeans.  In fact I'm getting this following Exception when executing through the final jar fine,


javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)

Open in new window


PLEASE HELP ME WITH THIS
0
 
for_yanCommented:
Soem folks like in this site:

http://old.nabble.com/using-SSL-in-a-development-environment-td19001545.html

recommedn to use this when creating socket factory:

    SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
                        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

If this part is in the code you can access, try it.
0
 
CEHJCommented:
Set the jvm-arg -Djavax.net.debug=ssl when you execute the jar from the command line. Set the same arg to your Ant run task and compare the two
0
 
snajalmAuthor Commented:
It ended up that Netbeans didn't want to include the JVM Options in the build.xml file and I had to manually put them in main.  Such unpredictable IDE.  Anyhow, my deepest appreciation CEHJ for bearing with me in solving this issue!

public static void trustStore() {
        Properties systemProps = System.getProperties();
        systemProps.put("javax.net.ssl.trustStore", "jssecacerts");
        System.setProperties(systemProps);
}
0
 
CEHJCommented:
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 20
  • 14
  • 11
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now