Forums Register Login

Creating JAR

+Pie Number of slices to send: Send
Hello All,

I have posted this https://coderanch.com/t/303446/JDBC/java/Creating-JAR 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

Alqtn

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

[ January 26, 2006: Message edited by: A Alqtn ]
[ January 26, 2006: Message edited by: A Alqtn ]
+Pie Number of slices to send: Send
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...

Description:

Here I have a file called "Hello.java" 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:


<project>

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

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

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


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

</project>

Note:
I am new to ANT, so please forgive me if any mistake
+Pie Number of slices to send: Send
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.
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 961 times.
Similar Threads
NPE
MS Access NullPointerException
java -jar [error] unable to access jarfile postgresql-8.4-702.jdbc.3.jar
Problem in displaying multiple search results
Searching problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:16:20.