1

I have a few jar files included in my application that i have added to librarys In net beans these can be read and used

I have tried to create an executable file in netbeans by Clean and build and i have all the necessary properties in build packaging set, however when i try to double click the jar created nothing happens. It is supposed to run the jar from my Main class

Now i tried to go to cmd terminal and do it from there using:

java -jar myapp.jar 

I have added 3 different jars including sqlite-jdbc3.8.7, AbsoluteLayout, miglayout

but what was returned was:

Exception in thread "main" java.lang.RuntimeException: Could not load SQLite JDBC driver
        at myapp.database.DatabaseConProvider.<init>(DatabaseConPr
ovider.java:18)
        at myapp.presenter.AppPresenter.<init>(AppPresenter.java
:32)
        at myapp.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: org.sqlite.JDBC
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at myapp.database.DatabaseConProvider.<init>(DatabaseConPr
ovider.java:16)
        ... 2 more

The problem seems to be that its not being able to access the jar files that have been added to the project, because once I execute clean and build the /dist folder in the project only has myapp.jar but should also have README.txt and a lib folder which contains all the librarys. As seen in:

http://netbeanside61.blogspot.co.uk/2009/08/making-executable-desktop-application.html

I am using windows 8 with netbeans 8.0.2

fooll
  • 39
  • 8
  • Did you enable "copy dependent libraries" in the Packaging section of the project properties? –  Mar 28 '15 at 10:47
  • yes i have and it still gives me this error im not sure why it doesnt load my jars if i have done it properly – fooll Mar 28 '15 at 11:06
  • @fooll : Have you seen my answer ? – moskito-x Mar 31 '15 at 11:18
  • when you run `ant clean jar` from the CLI, show the `tree` for the `dist` folder. In that folder, are all your runtime dependencies there? Specifically, the three JAR's which your project depends upon? – Thufir Mar 09 '16 at 11:21

2 Answers2

1

With a explorer you can go to the structure of a .jar file . (Or rename extension .jar to .zip)

  • possibility 1
    look at the MANIFEST.MF is the there something like

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.7.0_51-b13 (Oracle Corporation)
Class-Path: lib/sqlite-jdbc-3.8.7.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: Find

here the sqlite-jdbc-3.8.7.jar is in the lib/ folder outside GUIFormExamples.jar

enter image description here

  • possibility 2
    content of sqlite-jdbc-3.8.7.jar is added to appxx.jar

enter image description here


  • Case 1
    put the lib folder in the same folder where your appxx.jar is

  • Case 2 must work out of the box

moskito-x
  • 11,832
  • 5
  • 47
  • 60
0

How do you manage your application dependencies? I encourage you not to simply "add jars to your netbeans" - user some kind of project/dependency management tool instead - Maven or Gradle.

Then, in case of maven, check this answer: https://stackoverflow.com/a/574650/3080422

Porting your application to maven/gradle project won't take much time (but unfortunately, learning a tool definitely will...) and you gain a lot of flexibility.

Community
  • 1
  • 1
slnowak
  • 1,839
  • 3
  • 23
  • 37
  • "Netbeans uses Maven, and maven has lib-dependency plugin that generates such entry automatically, scanning all dependencies in your POM file" my friend has tried the same approach on her computer and it works for her on the same project and creates it by clicking the file however when i do it on my computer it doesn't work – fooll Mar 28 '15 at 11:09
  • @fooll git to the rescue! More specifically, github.com is free, there are others, as well. Not to drown you with irrelevancies, but there's probably a setting in NB which is, or isn't, in the project, which is why the discrepancy. FWIW, the pain and hassle of, specifically, gradle is, IMHO, worth it. NB supports gradle with a plugin. – Thufir Mar 09 '16 at 11:19