aspose file tools*
The moose likes Beginning Java and the fly likes newbie looking for some help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "newbie looking for some help" Watch "newbie looking for some help" New topic
Author

newbie looking for some help

Glen Wilson
Greenhorn

Joined: Nov 24, 2004
Posts: 4
Have an issue, new to Java.
I'm trying to run java on the command line to insert some information into the database.

/usr/local/java/bin/java -classpath com/app/datur/ Blind
Exception in thread "main" java.lang.NoClassDefFoundError: Blind

/usr/local/java/bin/java com.app.datur.Blind
Exception in thread "main" java.lang.NoClassDefFoundError: com/app/datur/Blind

What does this mean?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This is a pain to get working some times.

1) Update your PATH so you don't have to specify the path to java.exe. I'm not sure if this is important, but might be if the JVM wants to use the path to find other parts of the JRE.

2) Point your classpath to the directory that contains the first part of your package name. In my case it's called "bin" and "com" is a subdirectory there.

3) Specify the full package & class name for your main class.

Here's how I start one of my programs. I use jars instead of a directory structure, but otherwise it's the same:

See if any of that helps
[ November 24, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4753
    
    7

This means that Java can't find the class files with the information you gave it on the command line. Let's say your source files are somewhere in your home directory:



To compile and run, the commands would be:

cd ~/src/project1
/usr/local/java/bin/javac com/app/datur/Blind.java
/usr/local/java/bin/java com.app.datur.Blind

Also, make sure you have the package declaration in Blind.java:

package com.app.datur;


Junilu - [How to Ask Questions] [How to Answer Questions]
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
/usr/local/java/bin/java -classpath com/app/datur/ Blind
Exception in thread "main" java.lang.NoClassDefFoundError: Blind


If you are using Windows, try using \ instead of /.

Please check that Blind.class is actually in directory "com\app\datur".
Also, do a "dir" in Windows or "ls -l" in LINUX/UNIX just before you issue the java command and make sure that you see directory "com".


Mike Gershman
SCJP 1.4, SCWCD in process
Glen Wilson
Greenhorn

Joined: Nov 24, 2004
Posts: 4
I'm on Solaris.

The full path to the Blind file is: /opt/application/test1/webapps/debatur/WEB-INF/classes/com/app/datur/Blind.class

file

package com.app.datur;

import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.*;
import java.util.StringTokenizer;

import com.app.dat.ApplicationCon;
Glen Wilson
Greenhorn

Joined: Nov 24, 2004
Posts: 4
Think I got it.
Glen Wilson
Greenhorn

Joined: Nov 24, 2004
Posts: 4
Except now I get

Exception in thread "main" com.dread.layer.DataException: Can't find DB Driver make sure it is on your classpath
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at com.dread.layer.ConnectionFactory.__beginFactory(ConnectionFactory.java:231)
at com.dread.layer.ConnectionFactory.loadFactory(ConnectionFactory.java:121)
at com.app.datur.Blind.main(Blind.java:5)

mysql driver is in /opt/application/test1/webapps/debatur/WEB-INF/lib
[ November 24, 2004: Message edited by: Glen Wilson ]
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4753
    
    7

you need to add the jar file that contains the mysql driver class to your classpath
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
If you need help with setting your CLASSPATH, check out this page on our friendly FAQ. Scroll down about half way for the instructions on how to do this in Linux. It should be similar in Solaris since it is basically a variant of Unix.

HTH

Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie looking for some help