Reputation: 10176
when I go to the directory which contains the .java class, which in turn contains the main() method, and run javac Application.java
, I get this error:
And then when I run java Application.java
just to see the output, I get this error:
Error: Could not find or load main class Application.java
Apparently it doesn't even recognize the class there.
This is the output of java -version
:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
This is the output of javac -version
:
javac 1.8.0_45
Not really sure what's wrong.
Any ideas?
Upvotes: 1
Views: 1840
Reputation: 4837
Based on what you comment you can put all 3rd part jars into some folder and run javac -cp "<folder_with_jars>" Application.java
.
If there isn't any compile errors it will generate the class file and then you can execute with java Application
Upvotes: 1
Reputation: 10560
Your application is using some 3rd party libraries like Spring. You need to tell java where to find these libraries. You can copy them somewhere and refer to them by the classpath configuration. To make things simpler, look into maven - dependency management system.
Upvotes: 1
Reputation: 20520
The reason it's not managing to compile your application is that you're importing classes from elsewhere, but you've not told the compiler where to find those classes. You need to add them to the class path for the compiler. In this case, you're importing some classes from the Spring framework, but you haven't supplied the relevant .jar
files to the compiler so that it knows where to find the classes you're importing.
The second error you get is when you try to run your program, but you can't because you haven't managed to generate a compiled version.
I would very strongly recommend that you download Eclipse or IntelliJ IDEA or a similar IDE, and use that for your development and compilation. It will handle pretty much all of this for you. You have a painful road ahead of you if you want to compile from the command line.
Upvotes: 3