A Java class’ fully qualified name refers to its name prefixed with its package name. To run the compiled class, you need to type in the fully qualified class name in the command line. This will save the compiled binary file (the. You can change the working directory by using the cd command on any operating system.Ĭompile Test.java by running the following command: package testPackage javac testPackage/Test.java ![]() ![]() Now, open a new terminal and make sure your working directory is the same as the one that contains the package folder. In your file manager application, a package is represented as an independent folder. In this simple example, using a package will help you visualise how Java’s classpath works. Packages are used in Java in order to group similar classes together or provide a unique namespace for classes. Place it in a package called testPackage. Of course, the way to rectify this problem is to manually specify the classpath by either using packages or specifying the classpath.Īt this point, if you'd like to refresh your memory of Java classes, check out our guide for creating classes in Java. When the JVM is unable to locate the main class, it’s often because it's looking for the corresponding. class files can be found in a JDK package or directory. ![]() It can be set using either the -classpath option when executing a program or by setting the system CLASSPATH environment variable.Īs the name suggests, it's simply a file path where the. The classpath is the file path that the Java runtime environment searches for classes and other resource files. Why Was the Main Class Not Found?īefore we try to understand how and why JVM was not able to find the main class, we need to understand the concept of Classpath in Java. Read on to find out how you can get rid of this error once and for all. But this issue is actually less intimidating than it seems to be.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |