-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Running Hibernate Without An Installer.
PostPosted: Fri Jul 17, 2009 5:02 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
Hi there,

The application I am currently writing needs to open and use a database inside itself, and be able to persist it between sessions.

However I cannot run an installation program as the people it is being written for are not exactly computer savvy.

I have read the short tutorial, and most of the free chapter of the book but I am no closer to knowing if, and how, hibernate can be used for this process.

My current plan for distribution is to have the users just unzip a folder containing my program (and associated files) and then for it just to be run. This means that the java program can run class paths after opening.

However I am confused upon the code that is used to start up the database and connect to it, when I don't know the starting location of the program, nor can I run an install program first.

If someone could point me to either a tutorial which explains this, or the source code to initiate and connect to the database, it would be very much appreciated.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Fri Jul 17, 2009 5:32 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You could use H2 (or HSQLDB) and start it in in-process-mode. There is a good tutorial on the H2-Homepage. In hibernate.cfg.xml you name the relative path to the database-"Folder".


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Fri Jul 17, 2009 5:39 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
H2 only comes as a .exe installer. Therefore i can not use it. I will not have access to the machines the program will be run on.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Fri Jul 17, 2009 6:37 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
H2 is one jar-File. Download the platform independent version and read the first pages of the tutorial.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 3:32 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
Don't be silly. You don't install .jars you just run them.

Neither do you install quite alot of .exe as they just run.

For proof, please see calc.exe


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 6:42 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
Ok H2 is now up and running and i can perform SQL on it.

Now i wish to intergrate hibernate. I have it downloaded and in a seperate folder, however calling Class.forName("org.hibernate"); is not importing it during runtime as it says it can't be found.

Does anyone know the correct class name i need to import (along with persistance if need be).


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 6:49 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Create a hibernate.cfg.xml and set the properties you need for H2. Using the connection.url below puts your database files into the folder "folder" (relative to your "application directory") and creates a DB named "dbName".

<property name="connection.url">jdbc:h2:folder/dbName</property>
<property name="connection.username">user</property>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.password">password</property>


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:00 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
I have all of that, my problem is importing the hibernate class files as i can not set the javaclasspaths manualy i have to use Class.forName() to import them during runtime. Howeveri do not know the names of the nessercy jar to get hibernate to work.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:17 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Why can't you set the classpath when starting your application? Create a MANIFEST in your JAR. List alle the libs from the "required" folder, hibernate3.jar and a suitable slf4j-Logger (e.g. log4j => google: slf4j), your h2.jar and you are done.
You don't have to set the systemwide CLASSPATH-Variable. (Or am I missunderstanding you?)


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:30 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
I have no idea if that'll work. Let me go do some research on MANIFEST as i've never had to use it before.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:34 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
If you don't want a MANIFEST-File, create a bat/sh-file and name the jar-Files there via java -cp jar1.jar;jar2.jar... It's just the easiest way if you want to reach (stupid) Windows users, that get some pain when they see a black box with fixed width fonts. ;-) They can double click the jar and it works (if WinRAR, WinZip or others didn't grab the extension...).


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:44 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
heh yes this program is probably going to be used by mostly computer illiterate windows users, hence the lack of manual classpath setting.

Just wrote a manifest File, it didn;t work though :(

Code:
Manifest-Version 1.0
Class-Path Database/Hibernate/antrl-2.7.6.jar Database/Hibernate/commons-collections-3.1.jar Database/Hibernate/dom4j-1.6.1.jar Database/Hibernate/javaassit-3.9.0.GA.jar

Database/Hibernate/jta-1.1.jar Database/Hibernate/slf4j-api-1.5.8.jar Database/Hibernate/hibernate3.jar
Created-By 1.6.0 (Sun Microsystems Inc.)


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 7:57 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You have to take care of
- max. length of a line in manifest
- spelling (antlr... not antrl!)
- location of the jar-Files at runtime

Having a stacktrace would be nice. If I think of it this evening, I'll post you the configuration of a simple project that worked for me.


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 8:03 am 
Newbie

Joined: Fri Jul 17, 2009 4:54 am
Posts: 17
Location: Near London
When i run the project from netbeans it opens fine.

When i open with the jar i get a dialog

Title: Java Virtual Machine Launcher
Msg: Failed to load Main-Class mainifest attribute from EPOS-main.jar

(yes i fixed the typo first)


Top
 Profile  
 
 Post subject: Re: Running Hibernate Without An Installer.
PostPosted: Mon Jul 20, 2009 8:15 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Add the MainClass-Attribute to your manifest. (There has to be an empty line at the end of the manifest. Or was it two lines?!? Can't remember...)

Example:
Main-Class: a.b.c.d.e.MainClass


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.