0

I have been testing the examples (HelloWorld.java) from Sphinx4 with Eclipse, but I would like to compile and run them from the command line. The application needs 5 .jars to be able to run, I have read that in order to compile a java class with multiple .jars I need to execute the following command (as an example I will show short names):

javac -cp one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld.java

The console does not throw any error messages:

parias001@parias001-pc:~/Projects/citadel_voices/sphinx_test > javac -cp jsapi.jar:sphinx4.jar:TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar:WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar:WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar HelloWorld.java
parias001@parias001-pc:~/Projects/citadel_voices/sphinx_test > 

I think that the compilation succeeded. Now I would like to run the application, I read that in order to do this, I have to execute the command as follows (Using short name example as before):

java -cp one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld

This is the message that the console throws:

parias001@parias001-pc:~/Projects/citadel_voices/sphinx_test > java -cp jsapi.jar:sphinx4.jar:TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar:WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar:WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar HelloWorld
Error: Could not find or load main class HelloWorld

I don't know what is going on here, I should also say that I do not have a lot of experience using external .jars.

The names of the .jars are:

  1. jsapi.jar
  2. sphinx4.jar
  3. TIDIGITS_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar
  4. WSJ_8gau_13dCep_8kHz_31mel_200Hz_3500Hz.jar
  5. WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz.jar

I appreciate any help you can give me.

barryhunter
  • 20,886
  • 3
  • 30
  • 43

1 Answers1

1

You have to include current directory in classpath:

java -cp .:one.jar:two.jar:three.jar:four.jar:five.jar HelloWorld

Note the leading .:


From this reference:

The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.

  • Thank you very much for this information. I included the "." but now it shows another error: `Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld (wrong name: edu/cmu/sphinx/demo/helloworld/HelloWorld)` I guess I know what the problem is, in the HelloWorld.java code, there is included a package as well: "package edu.cmu.sphinx.demo.helloworld;" If I need to compile with a package, should I follow the same instructions as before? Thank you. – AmirBayareh May 27 '15 at 18:23
  • I just commented the line with the package, now everything is working as it should! Thank you very much! – AmirBayareh May 27 '15 at 18:34
  • If you don't want to comment the package you have to put classes in a hierarchy of folder corresponding to the path (ie. package a.b.c => path a/b/c) –  May 27 '15 at 19:42