I've got the .jar to run from a command line but still can't get it to
run from within NetBeans.
How did you build the jar? I'm curious, because as I mentioned above, if
the project properties doesn't include the JDBC driver jar in the
libraries section then I'd expect it to fail to compile due to the same
missing class files. If the JDBC jar is mentioned in the project
properties then it really ought to be included in the jar manifest
classpath and be copied to the dist/lib directory.
I suspect that maybe it's how I moved the
project from one machine to another. I simply copied the project from
the initial machine to the second macine. Then, with NetBeans, on this
2nd machine, opened and clean compiled the project.
This may well be the root of the problem. I've had problems in NetBeans
moving projects from one place to another. Somewhere in the hidden
depths of the nbproject directory structure lurks a set of files
containing various information about the project properties. When a
project is moved to another location some of that information becomes
invalid, but that isn't necessarily reflected in the NetBeans project
properties dialogs, and cannot be fixed via them. You might be able to
edit those files and fix the problem if you can identify the correct
file/property which needs changing - and you might also break it even more.
I do have a recollection of a discussion on this NG about NetBeans
dist/lib and under what circumstances a jar file would not be copied to
the dist/lib directory. I think one of those might be when an external
project was imported, the new imported project isn't of the correct type
and some rules in the ant scripts fail to get executed and the jar
doesn't get copied, or added to the manifest classpath.
When I want to move a project I rather create a new project rather than
try to import an existing one. I then move the source tree into the new
project src tree. NetBeans picks this up quite well. It does mean that
it's necessary to re-create all the project properties, but it can be
worth it.
Now, the .jar from that compile runs from the command line but I get
the error
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
when I run from within NetBeans.
It looks like NetBeans doesn't think your project is an application.
It's not packaging it correctly.
If you don't get compilation errors the NetBeans knows that the JDBC jar
needs to be on the compilation classpath. It's just not creating the
correct run-time classpath because the project is not the correct type,
even thought it may look like it is. See above.
I went to NetBeans, Tools -> Libraries. Using "Add JAR/Folder" under
Library ClassPath I added
C:/Program Files/Java/jre6/lib/ext/mysql-connector-java-5.1.13-bin.jar
When I did that I noted that on the left side, unde Libraries, I have
MYSQL JDBC Driver
But I can look at what it points to.
So, I'm still not having any luck get the project to run under
NetBeans.
Thanks fro your help.
If the project isn't too large I'd suggest you create a new project,
copy the source tree and set the relevant project properties.