|
|
Path problem in a jar
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: Accessing dynamic java classpath in Java classes - comp.soft-sys ...... nothing in the dynamic class path (those added with javaaddpath) ever gets printed out. This is causing a problem because there is a schema file in MyAPI.jar that I need ... getResourceAsStream() problem - comp.lang.java.programmer ...Hello, I have a problem with getResourceAsStream(). I'm ... There are already several directories in your class path for a web app. Is your "XQuery file" a JAR? How tu use multivalent pdf tools - comp.text.pdfFind out about the path where Multivalent.jar is and then issue something resembling the above ... error (invalid command) thanks anyway I will > look for resolve my problem ... Checking whether user has access to file/folder - comp.lang.java ...... which I run as: java -Djava.security.manager FileCheck <<path to file/folder>> The problem: Read ... If you want to go there, you should put your code in a jar file (give ... How to add jdom library into my jar file in eclipse - comp.lang ...One is to put the other jar's in a path 'known to the application jar' (same directory is ... I don't "support" eclipse, but I've had the exact same problem before ... having trouble adding jar fiel to libaries of the project - comp ...end up having to right click libraries, add jar/folders using absolute path not unc path "gg ... Nonlinear Curve Fitting Problem - comp.soft-sys.matlab having trouble ... shared library path problem - comp.sys.hp.hpuxProblem with SUID bit in executable - comp.sys.hp.hpux shared library path problem - comp.sys.hp.hpux try enabling SHLIB_PATH lookup in the executable, if ... java deployment for web: UnsatisfiedLinkError - comp.soft-sys ...Javabuilder.jar file from the MCR folder is in the same ... the runtime dll from MCR installation to windows PATH ... mcc -W 'java: .. problem - comp.soft-sys.matlab java ... custom class in java.* package - is it possible? - comp.lang.java ...... jdk 1.5 : "-Xbootclasspath/p:path Specify a semicolon-separated path of directires, JAR ... interesting in understanding why this is not a possibility for the problem ... graphshortestpath - comp.soft-sys.matlabShortest path problem - Wikipedia, the free encyclopedia In graph theory, the shortest path problem is the problem of finding a path between two vertices (or nodes) in a ... java - Problem with path in .jar file - Stack OverflowYou cannot execute an executable in the jar file. You must extract it before calling Runtime.getRuntime().exec(). Think again, Runtime.getRuntime().exec() use your OS ... Jar Path Problem... - Java - Bytes - Tech Commmunity - Discussion ...Jar Path Problem.... Java Forums on Bytes. ... I have written a java application , and i am using sounds , images which are placed in Sounds and images packages. 7/26/2012 1:22:58 PM
|
|
|
|
|
|
|
|
|