aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating JAR" Watch "Creating JAR" New topic
Author

Creating JAR

A Alqtn
Greenhorn

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

I have posted this http://www.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 ]
Ambika Kumar
Greenhorn

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...

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
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creating JAR