0

Whenever I build my project as jar(via NetBeans) it seems that it does not include the postgresql driver library. I remember doing it before without any problems on previous versions of NetBeans and Drivers. I cmd run something like:

C:\Users\Username>java -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImport\dist\OrdersImport.jar" C:\orders\sometextfile.txt

Should there be something extra to include in this line to add postgresql-9.0-801.jdbc4.jar? I did include library to lib inside of the project and it does work without any troubles if I run it from NetBeans directly. I've looked at my previous project where it did work, seems to be everything same, pathetic I just can't remember, help please.

2 Answers 2

3

There should be an entry in your MANIFEST.MF file that references the Postgres driver. And the driver needs to copied so that it's reachable from the real jar files location.

So your MANIFEST.MF needs to include something like this:

Class-Path: lib/postgresql-9.0-801.jdbc4.jar

If the JDBC driver is part of your NetBeans project, NetBeans should have copied it to dist/lib.

If you don't want to change the manifest file (or cannot), you need to manually reference all needed libraries on the command line. But then you cannot use the -jar option any longer:

java -cp postgresql-9.0-801.jdbc4.jar;OrdersImport.jar com.mypackage.MyMain C:\orders\sometextfile.txt

Remember that you have to specify the main class when using -cp or -classpath

Sign up to request clarification or add additional context in comments.

3 Comments

that is what I have in MANIFEST.MF: Manifest-Version: 1.0 X-COMMENT: Main-Class will be added automatically by build - Exactly what I would get in past, but now it has naughty behaviour for some reason :\
The Main-Class is not related to the classpath. The Class-Path entry is important.
Well as always my mistakes are magical, created new project>copied over all the code, tried to run new projet with same code and library- didn't like library this time, said something about cannot open zip file when given postgresql-9.0-801.jdbc4.jar, double checked filename still no use, downloaded jdbc3.jar - and magic, as if nothing terrible happened, works as clocks. Was it corrupted or something not sure, at times like this I am really depressed that I am probably going to spend all my life in this industry.
0

You would have to add the postgre jar to your classpath:

C:\Users\Username>java -classpath "location of postgresql-9.0-801.jdbc4.jar" -jar "C:\Users\Username\Documents\NetBeansProjects\OrdersImpo rt\dist\OrdersImport.jar" C:\orders\sometextfile.txt

1 Comment

-classpath (or -cp) is ignored when using -jar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.