Link to home
Start Free TrialLog in
Avatar of snajalm
snajalm

asked on

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??!
Avatar of for_yan
for_yan
Flag of United States of America image

What is the stacktrace of your exception - please post the details
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?

A Java Exception has occured - that can easily be about anything - before you make conculusion you should
look at the details of exception
Avatar of snajalm
snajalm

ASKER

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!
Your jar poerhaps is not executable jar
jar -jar myfile.jar

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

java -jar myfile.jar

try this and let us know
Avatar of snajalm

ASKER

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
You need to have this stuff from netbeans in the classpath or on the jar


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
appframework-1.0.3.jar is missing on the classpath

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

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
Avatar of snajalm

ASKER

But they're all there in Netbeans as can be seen in the image provided!
untitled.bmp
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
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
Avatar of CEHJ
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

Avatar of snajalm

ASKER

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

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

Should definitely be installed for you imo
Avatar of snajalm

ASKER

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???!
The application jar? You'll find it's at

<project name>\dist\<project name>.jar
Avatar of snajalm

ASKER

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??!
Try the following then look again
ant -f <path to build.xml in your project> jar

Open in new window

Avatar of snajalm

ASKER

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
Avatar of snajalm

ASKER

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...
http:#37000315 is the result of running the very last comment i posted?
Avatar of snajalm

ASKER

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!
Avatar of snajalm

ASKER

Any ideas or suggestions???!!!
What does the following give at the command line?
echo %ANT_HOME%

Open in new window

Avatar of snajalm

ASKER

%ANT_HOME%
Then you didn't follow my earlier advice.

http:#36998588
Avatar of snajalm

ASKER

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??!
Avatar of snajalm

ASKER

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??!
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
Avatar of snajalm

ASKER

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!
>> echo %JAVA_HOME%

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

Please post full current error(s)
Avatar of snajalm

ASKER

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??!
You can't run it like that - no wonder you're getting errors!
Avatar of snajalm

ASKER

Then how should I run it then??!   Shouldn't the jar file be able to run through the explorer??!
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
Avatar of snajalm

ASKER

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.  
Avatar of snajalm

ASKER

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
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
Avatar of snajalm

ASKER

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
SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of snajalm

ASKER

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);
}
:)