This question already has answers here:
Why this javac: File Not Found error?
(5 answers)
Closed 8 years ago.
I was using Java SE Jdk1.7.0_40 and it was working perfectly fine. I've no idea what went wrong, I've set the path many times through different ways. If I check in cmd like by writing javac or java -version, it results affirmative but when i write
javac hello.java i get this error..
javac: file not found: hello.java
Usage: javac
use -help for a list of possible options
I went through almost all of topics related to my problem but all are saying the same thing that is "to set the path, may be your path is not correct, etc etc". I've re-install java but still no use.
Is there any step by step procedure to check whether the path is actually responding or not?
Am using Windows 7 and current version of Java is SE jdk1.7.0_60
a thing more.. when I compile the java file from the folder containing that file, it works fine and generate .class file but when I execute the class file ..
java hello , i get this
Error: Could not find or load main class hello
may be i'm missing something..
Help...
There is no problem with javac not being on your PATH, since the error you see is an error from javac, which could only occur if javacis on your path and running.
The only possibility is that hello.java is not in the current working directory from which you are invoking the command. Putting the directory that hello.java lives in onto your PATH will not help here.
Related
This question already has answers here:
I could not understand why "javac: file not found: HelloWorld.java"
(2 answers)
Closed 2 years ago.
Can anyone tell me that why when I'm providing the whole path after typing like "javac C:\Java\MyFirstApp.java" then it is compiling. But when I directly go for "javac MyFirstApp.java" it is showing me file not found.
Because you are not in same directory where .java is placed. Change directory to app folder using cd command and type only javac MyfirstApp.java
From what I remember, to execute the program you don't need to inform the extension.
Go to your project's folder and try:
javac Main.java
java Main
This question already has answers here:
How do I run Java .class files?
(4 answers)
Closed 4 years ago.
I crawled through the forums and tried a few things, I am just trying to run a java file I downloaded from github that I did not make. I compiled it fine, but am now stuck. Here's what I've done so far (In the downloads directory for both):
java.Randomizer,
and
java -cp C:\Users\enajo\Downloads\Randomizer
Both resulted in Error: Could not find or load main class
The file is located in downloads and is named Randomizer.class with the classname being ca.pogo4545.randomizer. What am i doing wrong?
If you declared a package name (that you mentioned as classname) the run command line must include the name of it:
java ca.pogo4545.randomizer.Randomizer
But in this case the file also must be in a directory structure that represent the same package, and if you using more than one class you must include the -cp arguments
First of all the name of the class must be the same as the name of the file .
Java and Javac are case-sensitive.
Compile like : javac HelloWorldApp.java
And run like : java -cp . HelloWorldApp
This question already has answers here:
Error: Could not find or load main class [duplicate]
(22 answers)
Closed 5 years ago.
I am trying to run these programs, but I am getting
Error: "Could not find or load main class"
Here's a screenshot of me trying to run the programs in cmd line:
Windows Powershell Screenshot:
This makes no sense to me seeing as how the files compiled just fine, which would imply that the main class was able to be found.
If anyone could explain what's going wrong I would appreciate it very much, thank you.
The UDPServer code:
The UDPClient code:
You have defined a package serverClient; at the top of both files.
So you should be having a directory named serverClient with your .class files.
if you wish to execute using java command line, you should execute from the src directory like this
PS ...\Programming Assignments\src > java serverClient.UDPServer
PS ...\Programming Assignments\src > java serverClient.UDPClient
It would be useful if you post your code here. But if I try a shot in the dark I would say that your filename doesn't match the classname in your Java file.
When running javac you pass in the paths to files you want to compile - hence those files are implicitly on the classpath. When running java you aren't passing in any files explicitly, so you have to include the current directory in the classpath in order for the JVM to know to look there.
$ javac Foo.java
$ java -cp . Foo
I use this Bash function pretty often for quick JVM/JDK experiments, if you want to try to replicate it in Powershell.
It's one of those cases where the current working directory probably should be on the classpath by default ~90% of the time, but it can't be in order to accommodate that last 10%. (Whether that's a good design decision or not is debatable, of course).
You are:
In the wrong directory. You should be in the directory that contains serverClient.
Using the wrong commands. They should be:
javac serverClient/*.java
java serverClient.UDPServer
java serverClient.UDPClient
This question already has answers here:
What does "Could not find or load main class" mean?
(61 answers)
Closed 6 years ago.
In my pc I'm always having a problem with running my java code in cmd . It shows "error loading main class" (though I commented out project name, set the classpath,set the PATH variable, but still no change) all the time. My teacher told me to create a new file and store my .java files there and edit it with notepad++ and create a .bat format file.
But I'm not sure about the whole process because I tried to do that it showed error again "error loading main class" (may be I missed some steps). Can anyone please help me with this?
Any help would be really appreciated.
Let's assume you have this directory layout:
myproject/
src/
mypackage/
MyClass1.java
MyClass2.java
target/
... and let's also asume that you open a shell with myproject as the working directory.
You should compile your source code and store the produced .class files into the target dir. For example:
javac -d target src\mypackage\*.java
And finally, to execute the main method in MyClass1, you should execute this:
java -classpath target mypackage.MyClass1 <arguments...>
Of corse, if you needed more third-party libraries, then you must add them to the classpath:
In Windows:
java -classpath target;library1.jar;library2.jar mypackage.MyClass1 <arguments...>
In Unix:
java -classpath target:library1.jar:library2.jar mypackage.MyClass1 <arguments...>
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
javac not recognized
I'm starting in the world of programming in java and I have run across a big problem: i cant compile my programs. when I type the javac command in cmd.exe(im using Windows 7) it displays this:
'javac' is not recognized as an internal or external command, operable program or batch file.
So I can't even test my first program.
I found in a book the following command:
set path=%path%;c:\java\jdk1.6.0\bin
but it doesnt work either.
I downloaded the newest version of the Jdk package just 2 weeks ago.
Look through your C drive for the c:\java folder and make sure you have version 1.6.0 of the jdk
c:\java\jdk1.6.0\bin
This will only work if you give it a path that actually exists. If you don't have 1.6.0, then type in:
set path=%path%;c:\java\<YOUR_ACTUAL_JAVA_VERSION_DIRECTORY>\bin