Environment variable wrongly set

B

bruce

I went to set the System Classpath for my JDBC Connect and
accidentally set the INCLUDE variable. Can I back that setting out by
doing a System Restore to a system copy before I made the mistake?

Thanks.

Bruce
 
L

Lew

I went to set the System Classpath for my JDBC Connect and
accidentally set the INCLUDE variable. Can I back that setting out by
doing a System Restore to a system copy before I made the mistake?

I don't think so, but that is a Windows question, not a Java question, and I'm
not sure.

Even if it did, it would have other effects as well, and is a huge overkill.

Setting the CLASSPATH is not really the best way to set classpaths, usually.
 
M

markspace

I went to set the System Classpath for my JDBC Connect and
accidentally set the INCLUDE variable. Can I back that setting out by
doing a System Restore to a system copy before I made the mistake?

Thanks.

Bruce


Yeah, what Lew said. Just change INCLUDE back. If you don't know,
leave it blank. Then if you find an error, fix it.

This stuff probably should be set in a script where the effect is local,
rather than system wide, so you can set different variables for
different runtime environments.
 
B

bruce

Yeah, what Lew said.  Just change INCLUDE back.  If you don't know,
leave it blank.  Then if you find an error, fix it.

This stuff probably should be set in a script where the effect is local,
rather than system wide, so you can set different variables for
different runtime environments.

Okay.. Need some help here. I was setting up to run JDBC mysql
connect under NetBeans and also to run Java jar's from the command
line. How do I do this, other then to set the system environment
variable, CLASSPATH. What would a "script" look like? My knowledge of
scripts goes back to .bat files? That knowledge is so old, I've
forgotten how to write one!! How about DOS 3<grin>!!!

Thanks...

Bruce
 
N

Nigel Wade

Okay.. Need some help here. I was setting up to run JDBC mysql
connect under NetBeans and also to run Java jar's from the command
line. How do I do this, other then to set the system environment
variable, CLASSPATH. What would a "script" look like? My knowledge of
scripts goes back to .bat files? That knowledge is so old, I've
forgotten how to write one!! How about DOS 3<grin>!!!

Thanks...

Bruce

NetBeans should handle it all for you, if you've created an NetBeans
project correctly.

The application jar should be in the dist subdirectory of the project.
Any other jar libraries which the app. jar requires should have been
copied to the dist/lib subdirectory. The manifest of the application jar
should set the classpath to include all necessary jar's from the
dist/lib sub-directory.

Then you ought to able to run the jar by the command (as output by
NetBeans during the build)

java -jar <path-to-project>/dist/<application>.jar

If that's not working then you need to look into why NetBeans isn't
creating the correct dist/lib/manifest setup, rather than messing with
the classpath. Besides, if your executable is a jar, and you run it with
java -jar then no amount of messing with CLASSPATH, or the -cp
command-line argument, is going to help.

If your application requires the JDBC MySQL connector then you should
add it to the project properties in NetBeans. In the project properties
section "Libraries" add that jar to the project (you generally need to
do this anyway so NetBeans can find the class files to compile it). Once
you've done this the jar should be copied to the dist/lib directory when
you build the application, and also added to the jar classpath in the
manifest.

If the jar library is one which you are likely to use frequently you can
add it to NetBeans list of jar libraries. This makes it easier to add to
subsequent projects, and easier to manage if you have to move the jar at
some later time. You do this via the Tools/Libraries dialog.
 
B

bruce

NetBeans should handle it all for you, if you've created an NetBeans
project correctly.

The application jar should be in the dist subdirectory of the project.
Any other jar libraries which the app. jar requires should have been
copied to the dist/lib subdirectory. The manifest of the application jar
should set the classpath to include all necessary jar's from the
dist/lib sub-directory.

Then you ought to able to run the jar by the command (as output by
NetBeans during the build)

 java -jar <path-to-project>/dist/<application>.jar

If that's not working then you need to look into why NetBeans isn't
creating the correct dist/lib/manifest setup, rather than messing with
the classpath. Besides, if your executable is a jar, and you run it with
java -jar then no amount of messing with CLASSPATH, or the -cp
command-line argument, is going to help.

If your application requires the JDBC MySQL connector then you should
add it to the project properties in NetBeans. In the project properties
section "Libraries" add that jar to the project (you generally need to
do this anyway so NetBeans can find the class files to compile it). Once
you've done this the jar should be copied to the dist/lib directory when
you build the application, and also added to the jar classpath in the
manifest.

If the jar library is one which you are likely to use frequently you can
add it to NetBeans list of jar libraries. This makes it easier to add to
subsequent projects, and easier to manage if you have to move the jar at
some later time. You do this via the Tools/Libraries dialog.

I've got the .jar to run from a command line but still can't get it to
run from within NetBeans. 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.

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.

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.

Bruce
 
J

John B. Matthews

bruce said:
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.

In the Projects window, right click on the Libraries folder to add your
new library to the project.
 
N

Nigel Wade

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.
 
T

Thufir Hawat

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.


It'll still compile, but will result in a run time exception.


-Thufir
 
T

Thufir Hawat

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.


While I could be wrong, I have to disagree here. Could be the wrong
driver, or it's invoked incorrectly, or something along those lines.

I do agree with the advice to just start a new project, though.


-Thufir
 
N

Nigel Wade

It'll still compile, but will result in a run time exception.


Sorry, you are correct. NetBeans will display lots of red !, and
underlined classes, indicating that the class definition is unavailable.
But it will still compile.
 
B

bruce

Sorry, you are correct. NetBeans will display lots of red !, and
underlined classes, indicating that the class definition is unavailable.
But it will still compile.

Thanks for all the suggestions. I like the one about creating a new
project and going from there. That's what I'm going to try..

Thanks again...

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top