Loading resources from the following paths: Error: Could not find or load main class HelloWorld comes when you are trying to run your Java program using java command with the main class as HelloWorld but Java is not able to find the class.Loading map: total_world_war, from: C:\Users\Master\triplea\downloadedMaps\total_world_war-master.zip In order to solve this error, you must know how Java find and loads the classes, that's a little bit complex topic for beginners, but we will touch the same base here. For the curious reader, I would suggest reading my post How Classpath works in Java, a must read for a beginner. For now, you just remember that there is an environment variable called CLASSPATH which includes directories where Java looks for all class files and if it doesn't find your main class there then it throws "Error: Could not find or load main class XXX", where XXX is the name of your main class. Since many Java programmer is now started programming using Eclipse they face this issue when they first try to run their Java program from command line. In Eclipse, it's easy to compile and run the program because Eclipse takes care of all Classpath setup, but when you run your Java program from command line, CLASSPATH environment variable comes in picture. Personally, I don't like this environment variable and doesn't define in my environment variable, because its confusing and source of so many classpath related issue. Instead, I use -cp or -classpath option with java command to run my program. This way you always know which JARs are included in your classpath.įor beginners, another important thing to understand is the difference between PATH and CLASSPATH, you must know that PATH is used locate system executable, commands or. It is also used to locate native libraries used by your Java program. While, CLASSPATH is used to locate the class file or JAR files. Solving Error: Could not find or load main class HelloWorld It's Java class loader who looked into CLASSPATH for loading classes.Ĭoming back to the problem in hand, if you are a beginner in Java, who are able to run the program from Eclipse but getting "Error: Could not find or load main class HelloWorld" when trying to run the same program from the command line then follow the steps given here to solve it. Unfortunately beginner's book like Head First Java, which many developers used to learn Java, doesn't teach you how to deal with this kind of errors. Install4j standalone updater command line switches how to# You need to build this skill by doing active development. In order to understand the problem little better, let's reproduce it. This is one of the most important troubleshooting skill which will help you a long way in your career. Half of the problem is solved when you are able to reproduce it.įor our purpose we will use following HelloWorld program for our testing, interestingly I have named it HelloHP and it resides in a package called "dto". * Error :Could not find or load main class * Simple Java program to demonstrate following error I have purposefully chosen a class with a package instead of HelloWorld in the default package because many programmers get "Could not find or load main class" error when they try to run a class which is inside a package. (see the separator, in Windows it's (semicolon) while in Linux it is (colon), also note we have included current directory in existing classpath. Install4j standalone updater command line switches windows# If you still face the issue of setting classpath, see this step by step guide to set the classpath. Same thing applies if you are running your program using -cp or -classpath option.Ģ) If you are running Java program from the directory, your. class file is and you don't have any CLASSPATH or -cp option then check whether your class is the in the package or not. If it's the in the package then go outside of the package directory and run java command with fully qualified name e.g. Install4j standalone updater command line switches windows#.Install4j standalone updater command line switches how to#.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |