1

When I run the maven project from Netbeans 11 everything works fine, but when I run it from command line with: java -jar program.jar I cannot connect to the mysql. I have also tried to run like I understood from similar posts on the same topic with: java -classpath mysql-connector-java-8.0.17.jar -jar program.jar Same problem. Is there a way to set up NetBeans 11 to generate the distribution jar able to use the jdbc driver?

florin.iliescu
  • 302
  • 4
  • 10
  • 1
    You don't want to do this. You want to be able to update it independently, or even for the user to be able to do so. You want to distribute it separately and name it in your JAR file's Manifest `Class-Path:` entry. – user207421 Oct 01 '19 at 04:12
  • I think I did that, but still not working. Running with classpath flag, or adding `Class-Path: mysql-connector-java-8.0.17.jar` to `manifest.mf` should not resolve this? – florin.iliescu Oct 01 '19 at 04:15
  • 1
    You can't use `-classpath` when using `-jar`. When using `-jar`, the class path must be specified in the manifest of your jar. – Mark Rotteveel Oct 01 '19 at 07:25

1 Answers1

0

I managed to solve this by adding mysql-connector-java-8.0.17.jar to Project Libraries like it was suggested in this post: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse, but also I needed to copy mysql-connector-java-8.0.17.jar in the same folder with the distribution jar.

florin.iliescu
  • 302
  • 4
  • 10