File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Creating JAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating JAR" Watch "Creating JAR" New topic

Creating JAR

A Alqtn

Joined: Jan 02, 2006
Posts: 14
Hello All,

I have posted this topic on the JDBC forum but could not get any help.

I have created a simple Java application (ReadingAccessDB) that reads table rows from MS Access database. The program packages the java class file in jdbc folder (package jdbc; ), and the database file is one level up.

here is the code:

For example if the class file is in C:\jdbc\ReadingAccessDB.class, the database file "carpets.mdb" is in C:\

when using JVM "C:\java jdbc.ReadingAccessDB", the application works fine. However, I want to archive the application with the database file in a jar file so that it can be executed from any location. Could some one help


[ January 26, 2006: Message edited by: A Alqtn ]

[ January 26, 2006: Message edited by: A Alqtn ]
[ January 26, 2006: Message edited by: A Alqtn ]
Ambika Kumar

Joined: Jan 27, 2006
Posts: 13
I think using ANT you can solve it.
As you know using build file can make use of jar file.

Here is a sample program in ANT. I am just tyring, it is not sure. Anyway try...


Here I have a file called "" and it is inside "D:\AnT".
So change it with your file name and directory path to the specified file.

create a build file using this and

1) type -> ant compile
2) type -> ant jar
3) type -> ant run

or replace all with

ant compile jar run

Code is:


<target name="clean">
<delete dir="build"/>

<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="D:\AnT" destdir="build/classes"/>

<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/Hello.jar" basedir="build/classes">
<attribute name="Main-Class" value="Hello"/>

<target name="run">
<java jar="build/jar/Hello.jar" fork="true"/>


I am new to ANT, so please forgive me if any mistake
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Well to confirm what was said in your other thread and what I am pretty sure I told you a few days ago on another forum.

You cannot do this. You cannot embed your Access database in a jar and access it with JDBC. There are a number of technical impossibilities that make this a non-starter. You will have to ship the database as a seperate file (although you could deploy in one setup or zip file) and have it reside in a proper Windows directory.

There is no workaround that will make this (Access) work directly from a Jar.
I agree. Here's the link:
subject: Creating JAR
It's not a secret anymore!