So I'm currently working through the official JGroups tutorial here
I compile the class, specifying the correct JGroups class path, however when I run the SimpleChat, I get the following error message.
User#0001-Macbook:~/Desktop/JGroupsTutorial/src$ javac -cp jgroups-3.4.0.Final-2.jar SimpleChat.java
User#0001-Macbook:~/Desktop/JGroupsTutorial/src$ ls
SimpleChat.class SimpleChat.java jgroups-3.4.0.Final-2.jar
User#0001-Macbook:~/Desktop/JGroupsTutorial/src$ java -cp jgroups-3.4.0.Final-2.jar SimpleChat
Error: Could not find or load main class SimpleChat
You need to add the location of your .class file to your classpath.
For Mac/Linux:
java -cp .:jgroups-3.4.0.Final-2.jar SimpleChat
For Windows:
java -cp ".;jgroups-3.4.0.Final-2.jar" SimpleChat
Related
I have a problem.
I try to run my java program with the library.
When I use
java com/myProg
it works.
But when I try to pass classpath it can't find or load main class
java -cp com/lib/lid.jar com/myProgram
error:
Error: Could not find or load main class myProgram
Caused by: java.lang.ClassNotFoundException: myProgram
Try specifying after the -cp option only the root of the working directory and don't include the package name there. If you're running the java command from the dir of /com 's location, -cp . com/myProgram will be enough,otherwise you'll need the fully qualified name after the classpath.
Not sure of the necessity of the .jar file, you stated that first you ran only via
java com/myProg.
i'm new in compiler . i've read that i can generate xxx.flex file in cmd by this code :
java JFlex.Main xxx.flex
but i got this error :
Error: Could not find or load main class JFlex.Main
and for generating yyy.cup , i typed :
java java_cup.Main yyy.cup
but i got this error too :
Error: Could not find or load main class java_cup.Main
i confused ... what should i do ?
When you are invoking
java JFlex.Main xxx.flex
You ask java to load the JFlex.Main class and passing xxx.flex as parameter. As you do not tell java where is that JFlex.Main class, java is searching it in its classpath, and if you did not add the JFlex jar file to the class path, it results in the error message
Error: Could not find or load main class JFlex.Main
BTW, class names and namespaces are case-sensitive : in the JFlex jar file, the Main class is in the jflex directory, not JFlex so you need to invoke the jflex.Main class... unless you are using the a JFlex version prior to 1.5 where JFlex is legal.
To let java find the class:
either change the system class path (with the environment variable $CLASSPATH- or %CLASSPATH% in windows)
or just provide the location of the jar file the the java command with the -cp parameter
For example:
java -cp path/to/jflex-1.6.0.jar jflex.Main xxx.jflex
If the jar is in the current directory, you can just use
java -cp jflex-1.6.0.jar jflex.Main xxx.jflex
Or more simply, as it is an executable jar, you can omit the main class
java -jar jflex-1.6.0.jar xxx.jflex
Similarly, it seems that java is missing the CUP jar file while processing your yyy.cup file, you can fix it like for JFlex with
java -cp java-cup-11a.jar java_cup.Main yyy.cup
or
java -jar java-cup-11a.jar java_cup.Main yyy.cup
I'm starting to learn Java, and I am attempting to run the FrameDemo tutorial code found here: https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
I can compile fine with javac FrameDemo.java but when I try to run it with java -cp . FrameDemo I get this error:
Error: Could not find or load main class FrameDemo
I thought it was my classpath so I tried java -cp D:\projects\framedemo FrameDemo and got the same error.
Then I tried recompiling with javac -cp . FrameDemo.java and javac -cp D:\projects\framedemo FrameDemo.java and still got the same error when running java -cp . FrameDemo and java -cp D:\projects\framedemo FrameDemo. I also tried running java -cp . FrameDemo.class just for the heck of it.
Always I get Error: Could not find or load main class FrameDemo
What am I doing wong here? I've just downloaded and installed the latest JDK. The source code is exactly what is in the demo link above.
move all your .class files to a folder 'components'.
Then run this:
java components/FrameDemo
or
remove package components; from your source file, recompile and run :
java FrameDemo
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:
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
I appreciate any help you can give me.
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.
Hey I got this problem when running a java program through my cmd.
I use to external libraries : lwjgl.jar and slick-util.jar
when I compile
javac -d bin -sourcepath src -cp ;lib/lwjgl.jar;lib/slick-util.jar src/*.java
everything works fine
but when I try to run it
java -cp bin .;lib/lwjgl.jar;lib/slick-util.jar; Game
I get this error
Error: could not find or load main class .;lib.lwjgl.jar;lib.slick-util.jar;
Replace the space in the run command classpath with a classpath separator
java -cp bin;.;lib/lwjgl.jar;lib/slick-util.jar; Game
^
as an improvement to the run command you could use a classpath wilcards, for example
java -cp ".;bin;lib/*" Game
It is important to use quotes under Windows for this option