compiling and running java on windows
Posted
by
artur grzesiak
on Stack Overflow
See other posts from Stack Overflow
or by artur grzesiak
Published on 2013-11-09T15:50:44Z
Indexed on
2013/11/09
15:53 UTC
Read the original article
Hit count: 309
I thought the task should be fairly easy, but my understanding of javac and java in general is rather poor.
I am using Windows8 and would like to compile a single file.java
that makes use of other classes. I successfully (at least without any warnings) compiled my file by calling:
javac -cp relative_path_to_needed_classes relative_path_to_file_java\file.java
Now if I want to run the result of compilation (file.class
) by calling:
java -cp relative_path_to_needed_classes relative_path_to_file_java\file
I get:
Error: Could not find or load main class relative_path_to_file_java\file
I was trying a lot of combination to modify the -cp
(eg. by adding .\;relative_path_to_file;
) but still the closest where I get is:
Exception in thread "main" java.lang.NoClassDefFoundError :
relative_path_to_file\file (wrong name: file)
The file from (wrong name: file)
is the name of the file and the name of the public class within the file.
I was reading a lot on SO and other sources but could not figure out what is wrong.
Btw. as a result of compilation some other classes were created:
file$1.class
file$name1.class
file$name2.class
(where name1 and name2 are names of private classes within file.java
)
My questions are:
- What is (the most) probably source of my error / what am I doing wrong?
- What is the purpose of
file$1.class
? - What is the minimum I should specify in
-cp
? - May encoding play any role?
- Do every java class have to reside in a package?
- (rather not directly related to my issue) Do order of paths specified in
-cp
play any role in runtime?
© Stack Overflow or respective owner