LWJGL cannot find class error when using "java <class file>" command - java

I successfully compiled my source using this command:
javac -classpath "..\lwjgl-2.7.1\jar\lwjgl.jar" Game.java
However, when I try to run it using:
java -classpath "..\lwjgl-2.7.1\jar\lwjgl.jar" Game
, it gives me an error:
Error: Could not find or load main class Game
What have I done wrong!? :(
I am certain that there are no syntactical errors and class labeling anomalies.
EDIT: I've also tried running the program using this command, but still nothing. T.T
java -cp "..\lwjgl-2.7.1\jar\lwjgl.jar" -Djava.library.path="..\lwjgl-2.7.1\native\windows" Game

Here is the answer, after endless hours of sitting on my toilet...
java -cp "..\lwjgl-2.7.1\jar\lwjgl.jar"; -Djava.library.path="..\lwjgl-2.7.1\native\windows" Game
Note the semi-colon after the -cp. The SEMI-COLON. That was all that I was lacking. A FRIGGIN' SEMI-COLON.
I hope nobody commits the mistake I did.

It has to be
java -classpath "..\lwjgl-2.7.1\jar\lwjgl.jar" Game

Is Game.class inside of that jar file? If not, you probably need to include the path to the class file as well. For the current working directory, try:
java -classpath "../lwjgl-2.7.1/jar/lwjgl.jar:." Game
(Maybe that : should be a ; on Windows).

Related

Why can't I run java from the command line anymore?

I've been running java programs from the command line for 5+ years using the same process:
javac Program.java
java Program
This is suddenly not working. Compiling works, but when I try to run the program I get an error saying the class cannot be found.
However, now when I type this, it works:
javac Program.java
java Program.java
This is fine, but when I have a class that extends another, it isn't being found.
Here is how it looks on the command line:
C:\Drive\Java>javac Program.java
C:\Drive\Java>java Program
Error: Could not find or load main class Program
Caused by: java.lang.ClassNotFoundException: Program
C:\Drive\Java>java Program.java
Hello World
Is there something I could have done to cause this change? I noticed it started happening yesterday after a windows update.
The Class's name should be exactly the same with the file name, please paste the code or check it yourself.
I was able to resolve this issue. The problem was that I had added a CLASSPATH environmental variable that pointed to my java bin folder and this was causing the behavior. I deleted it and the problem was resolved.
I suggest you check if your computer system is compatible with your jdk version.
And support? x86 x64

I was able to compile my java code from PowerShell, but cannot run it

I was able to compile and run my java code from CMD, however when I try to run the same commands in PS, I am getting error messages. I have read and been told that CMD commands will work in PS, but the CMD commands are not working in PS
Here is the line that I am using to execute my program:
java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
I am running the command from the directory where my needed JAR files are located. The error message says...
The command stanford-corenlp-3.8.0-models.jar was not found, but does exist
in the current location. Windows PowerShell does not load commands from the
current If you trust this command, instead type: ".\stanford-corenlp-3.8.0-
models.jar".
Made the change and the code looks like this now.
java -classpath .\;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
Still getting the exact same error message. I have also tried going up a directory and no luck. I have looked all over StackOverflow and I have done my research.
Any help would be much appreciated.
Thanks.
Using .\ would work for one file, but since you have a number of files, you should reference the current directory in each one of those files.
java -classpath .\stanford-corenlp-3.8.0.jar;.\stanford-corenlp-3.8.0-javadoc.jar;.\stanford-corenlp-3.8.0-models.jar;.\stanford-corenlp-3.8.0-models.jar .\Test.TestCoreNLP
Java 6 also supports wildcards, as this answer indicates, so you might try simply this.
java -cp ".\*" .\Test.TestCoreNLP
I came here with similar trouble, and what I found is that when running like this:
java -cp .\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar com.ethoca.app.myapp
I would get help info. My discovery is that I need to double-quote my list of classpath, like:
java -cp ".\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar" com.ethoca.app.myapp

cmd "Error: Could not find or load main class" error

I've read through the other questions and have tried googling the solutions, but I couldn't find the solution I was looking for.
This program compiles and runs on NetBeans, but only complies on CMD. I WANT to get it running with CMD.
I'm not very good with Java - just starting out and this is a uni project.
The program is in a package chess. Move up a folder,
C:\Users\Nihir\Documents\chess> cd ..\
C:\Users\Nihir\Documents> java -cp . chess.Program
You have to use fully qualified names to invoke a class from the commandline. which would be "chess.Program" instead of "Program"
First of all return back to your program directory
cd..
Now simply give the command
java Program

Error: Could not find or load main class HelloWorldApp

I am pretty new to this but I seem to have a problem for a day now, and I can't get around it. Have looked over the other similar post but nothing worked. I just got the basic tutorial, made my Java file.
Used the javac HelloWorldApp.java command and got the class file.
But every time I try to run the java -cp . HelloWorldApp command, I get the Error: Could not find or load main class HelloWorldApp error. Pretty sure I am doing something wrong, just don't know what. I am on a Windows 7 machine with jdk1.8.0_31.
You can simply run your .class file with java filename command, provide you are running it from the src directory
Your current working directory may not be in your classpath, before running java class issue this command to include PWD into your classpath :
set CLASSPATH=%CLASSPATH%;.
java yourAppName

How to use a jar file in conjunction with another in Java from the command prompt

I am doing an assignment for class and I was given a jar file for the Display board and I have to code some basic functions for it in a separate Java file. Now, I need the Display to be called in the program I'm writing, and so I used:
(I'm using a window PC)
javac -cp lab1.jar;.Wrapping.java
However, every time I try this, it gives me this error:
javac: no source files
usage: javac <options><source files>
use -help...
Now, I've changed my directory to the proper folder and the file is in there, and still, I cannot get it to run. What am I doing wrong? I can get other programs to compile and run from the command prompt, it is just this one that I cannot. Any help?
If your command it posted as you ran it literally, without the space between . and Wrapping.java, you need a space there.
Try this command to compile:
set classpath=lab1.jar
javac Wrapping.java
OR
javac -cp lab1.jar Wrapping.java
Try this command to execute:
set classpath=lab1.jar;.
java Wrapping ::Make sure its class name with main()
OR
java -cp lab1.jar;. Wrapping

Categories

Resources