• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

JAVA Problem with classpath

Hi All,

I am almost new to Java and trying to learn some stuff. would appreciate help pls..

I am trying to learn about FREETTS (JAVA SPEECH SOFTWARE from SUN). I downloaded it and unzipped it..

It created some folders like

c:\javaspeech\FreeTTS\demo\JSAPI\HelloWorld

In this HelloWorld folder are these files..

HelloWorld.java
helloworld.au
and also run.bat

run.bat looks like this..

javac -classpath ..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\cmukal8.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.jar -d ..\..\..\classes *.java
java -cp ...\..\classes;..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\cmukal8.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.jar %1


so I did from DOS as run HelloWorld

It created HelloWorld.class in the following directory..

c:\JavaSpeech\FreeTTS\classes as from first statement in run.bat

now from 2nd statement, it should run HelloWorld..

it showed me this error..


Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld


Below is the whole thing I did in DOS..


C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>run HelloWorld

C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>javac -
classpath ..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\cmukal8
.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.jar -d
..\..\..\classes *.java

C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>java -c
p ...\..\classes;..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\
cmukal8.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.
jar HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld

C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>


Help me with this plz
0
irodov
Asked:
irodov
  • 5
  • 3
  • 2
  • +3
2 Solutions
 
CEHJCommented:
Try java -cp .; <then the rest of the classpath>
0
 
irodovAuthor Commented:
I tried this..


C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>java -c
p.; ..\..\classes;..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib
\cmukal8.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi
.jar HelloWorld
Unrecognized option: -cp.;
Could not create the Java virtual machine.



help plz
0
 
CEHJCommented:
There should be a space between the 'p' of cp and the dot for the current directory
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
vano42Commented:
the above solution is correct, however you need a space between -cp and ".;...".  Because you left out a space jvm did not recognize the -cp option
0
 
warsqlCommented:
In
C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>javac -
classpath ..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\cmukal8
.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.jar -d
..\..\..\classes *.java
the important part to note is -d ..\..\..\classes which means that compiled classes will be put in ..\..\..\classes.  Therefore, your classpath needs to include ..\..\..\classes, but in

C:\JavaSpeech\FreeTTS\demo\JSAPI\HelloWorld>java -c
p ...\..\classes;..\..\..\lib\cmuawb.jar;..\..\..\lib\cmukal16.jar;..\..\..\lib\
cmukal8.jar;..\..\..\lib\cmulex.jar;..\..\..\lib\freetts.jar;..\..\..\lib\jsapi.
jar HelloWorld

you have ...\..\classes.  Change this to ..\..\..\classes
0
 
irodovAuthor Commented:
warsql's solution is working for me, I really appreciate the help..

before i close this question, could you pls tell me what does classpath means? I mean, when we do java helloworld..

is it that it looks for all classes needed for helloworld to run looking in classpath.. and as it keeps on finding it, it keeps saying ok ok..

when i set my environment variable CLASSPATH=...

Now when i do java helloworld.. does JVM looks at this env. variable to find out all related classes..

does JVM looks at java -cp classpath first or environment variable classpath first .. it looks at both though right??

if i put  ..\..\classes in my classpath env. variable, will it include all classes in this directory..

so does it means that if i put ..\..\classes\helloworld in my classpath env. variable..

to run this class, i can run it from any directory.. like for example if i do..

c:\java helloworld it shud run because JVM will look in classpath env. variable, find this class and it will run..

am i understanding the classpath correctly..

this wud be my last bunch of questions.. sorry to bother you..

regards
0
 
CEHJCommented:
Actually i noticed the three dots/two dots thing too - but made an incorrect assumption: namely that anyone that can cope with such a mess of relative paths knows exactly what the difference is between the is and is aware of what is being used!

I'll let warsql answer your remaining questions, since he'll be taking the points, but will say that you should let Java's extensions mechanism work for you. If you put all those jar files in the \lib\ext directory of your active runtime, then theoretically you don't need a classpath at all. I myself hardly ever have one set.
0
 
irodovAuthor Commented:
CEHJ,

Thanks for your reply, actually I don't know much of relative paths and the whole mess above. I am just learning the stuff. It was a mistake in run.bat file which comes with FREETTS package from SUN for JavaSpeech.

I just ran as they told and got into this mess.

WARSQL, whenever you getta chance, cud u pls reply my rest q's and i will close the question. I just want to learn Java stuff and trying some experiments.. and so coming up with these questions..

CEHJ, I have tons of q's coming soon because I am playing lot in Java these days and ofcourse facing heck lot of problems.. hope u can help me with some..
0
 
CEHJCommented:
Sure ;-)
0
 
warsqlCommented:
The classpath is a list of directories and jar (or zip) files that is used by the java virtual machine (jvm or just vm) to find any and all classes needed to run your application.  The vm will use your system environment variable CLASSPATH as its classpath by default when an application is run.  You can override this behavior by specifying the -cp "(classpath)" option at runtime.  This hides the system environment variable CLASSPATH and uses the specified classpath instead.  You can specify %CLASSPATH% within your specified classpath to also include the system classpath.

There also is a special directory in your filesystem that will automatically be included in addition to whatever classpath is specified.  That directory, as CEHJ said, is the lib\ext directory in the vm directory that you are using.  This will be something like c:\j2sdk1.4.1\jre\lib\ext on your windows machine.  Whatever classes or jars you put in that directory don't need to be on your specified classpath.

Hope that clears that up for you.
0
 
CEHJCommented:
If you pass the parameter "java.ext.dirs" to this programme you can discover what your active extension directory is (often not what one expects):

public class Props {

  public static void main(String[] args){
    if(args.length > 0){
     for(int i = 0;i < args.length;i++){
      System.out.println(System.getProperty(args[0]));
     }
    }
    else {
      System.getProperties().list(System.out);
    }
  }
}
0
 
CleanupPingCommented:
irodov:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between warsql and CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now