Path problem in a jar

  • Follow


Hi all.

I created a .jar file that contains my program.  Thus, when I'm trying to 
execute my program in command line "java /jar MyJar.jar" for example, 
there's a problem.

When my application starts I read some data in a folder named 
"Data/Database/MyDataBase.mdb"

It works fine when I'm devloping it with my IDE, but its not working when I 
create the jar file to deploy it.  I double checked the jar file and 
everything is in.

So my question is, how can I make a refrence to a file in my jar file.

Best regards,
Phil 


0
Reply Philippe 8/15/2007 7:03:46 PM

>"java /jar MyJar.jar"
that should likely read:
java.exe -jar myjar.jar
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 8/15/2007 11:26:19 PM


Yeah typo error.
I found something about getressource() but I'm trying to find more about it.

"Roedy Green" <see_website@mindprod.com.invalid> wrote in message 
news:gs27c3t71h58nudckbprbn5sjnr99gttht@4ax.com...
> >"java /jar MyJar.jar"
> that should likely read:
> java.exe -jar myjar.jar
> -- 
> Roedy Green Canadian Mind Products
> The Java Glossary
> http://mindprod.com 


0
Reply Philippe 8/16/2007 4:04:16 PM

>Yeah typo error.
>I found something about getressource() but I'm trying to find more about it.
see http://mindprod.com/jgloss/image.html
and http://mindprod.com/jgloss/resource.html
The background might help you crack your problem.
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 8/16/2007 9:38:58 PM

Roedy Green wrote:
>>Yeah typo error.
>>I found something about getressource() 

Do you mean getResource(), in java.lang.Class?
(Note the one Upper Case, one 's').
If not, you may need to link to some JavaDocs for it.

>..but I'm trying to find more about it.

Here are the JavaDocs for Class.getResource()
<http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String
)>

>see http://mindprod.com/jgloss/image.html
>and http://mindprod.com/jgloss/resource.html

(To the OP - read those, Roedy's pages usually 
contain a swathe of good tips) ..but..

>The background might help you crack your problem.

..I am gonna' take a WAG that we already know enough.
I suggest this code should obtain an URL to the DB..
  // important to put the leading '/'!
  URL theDB = anObject.getClass().
    getResource("/Data/Database/MyDataBase.mdb")

HTH

-- 
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200708/1

0
Reply Andrew 8/17/2007 12:18:57 AM

> I suggest this code should obtain an URL to the DB..
>  // important to put the leading '/'!
>  URL theDB = anObject.getClass().
>    getResource("/Data/Database/MyDataBase.mdb")

Tx alot, it works for getting the ressource.  Thus I have another problem to 
run the jar.

URL theDB = this.getClass().getResource("/Data/Database/MyDatabase.mdb");
String g = theDB.getPath();
String myDB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= " + 
g.substring(1);
conn = DriverManager.getConnection(myDB," ", " ");

When I run it form my IDE it works.  But when running the jar (lets' suppose 
the jar is in c:\) I get the following error.

C:\>java -jar ProLamp_fat.jar
file:/C:/ProLamp_fat.jar!/Data/Database/MyDatabase.mdb
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid 
fil
e name.
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at database.BD.OpenDB(BD.java:47)
        ...

Maybe its a problem with the manifest ?  Here's mine :

Manifest-Version: 1.0
Created-By: Fat Jar Eclipse Plug-In
Main-Class: core.Main
Class-Path: ./

Any tips would be greatly appreciated.
Best regards,
Phil 


0
Reply Philippe 8/18/2007 3:08:07 PM

Philippe Massicotte wrote:
>> I suggest this code should obtain an URL to the DB..
>>  // important to put the leading '/'!
>>  URL theDB = anObject.getClass().
>>    getResource("/Data/Database/MyDataBase.mdb")
> 
> Tx alot, it works for getting the ressource.  Thus I have another problem to 
> run the jar.
> 
> URL theDB = this.getClass().getResource("/Data/Database/MyDatabase.mdb");
> String g = theDB.getPath();
> String myDB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= " + 
> g.substring(1);
> conn = DriverManager.getConnection(myDB," ", " ");
> 
> When I run it form my IDE it works.  But when running the jar (lets' suppose 
> the jar is in c:\) I get the following error.
> 
> C:\>java -jar ProLamp_fat.jar
> file:/C:/ProLamp_fat.jar!/Data/Database/MyDatabase.mdb
> java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid 
> fil
> e name.
>         at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
>         at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
>         at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
>         at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
>         at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at java.sql.DriverManager.getConnection(Unknown Source)
>         at database.BD.OpenDB(BD.java:47)
>         ...
> 
> Maybe its a problem with the manifest ?  Here's mine :

You aren't going to be able to run the database directly from the JAR, that 
is, the data cannot reside inside the JAR.  They need to reside in the file 
system.

It'd be running the database from inside a ZIP file (more correctly a TAR 
file, but that's the same for purposes of discourse).  You'd constantly 
rewrite the compressed file with every change to the database contents.  Not 
feasible.  The JAR format isn't made for that.

You need the database to reside in an accessible file system.

-- 
Lew


-- 
Lew
0
Reply Lew 8/18/2007 3:41:05 PM

> You need the database to reside in an accessible file system.

Thank you sire.  I'll proceed that way.

Have a nice day. 


0
Reply Philippe 8/18/2007 5:23:30 PM

>It'd be running the database from inside a ZIP file (more correctly a TAR 
>file, but that's the same for purposes of discourse).  You'd constantly 
>rewrite the compressed file with every change to the database contents.  Not 
>feasible.  The JAR format isn't made for that.
If you use JAWS, you can easily unpack your database from a jar  and
install it on the client hard disk. Have a look at the source code for
esper at http://mindprod.com/products2.html#ESPER
-- 
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
0
Reply Roedy 8/19/2007 1:45:06 AM

> If you use JAWS, you can easily unpack your database from a jar  and
> install it on the client hard disk. Have a look at the source code for

Thank, will take a look.
Best regards. 


0
Reply Philippe 8/19/2007 3:52:38 PM

9 Replies
202 Views

(page loaded in 0.155 seconds)

Similiar Articles:













7/26/2012 1:22:58 PM


Reply: