{"id":41928,"date":"2021-07-18T02:12:31","date_gmt":"2021-07-18T02:12:31","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=41928"},"modified":"2021-07-18T02:12:33","modified_gmt":"2021-07-18T02:12:33","slug":"comp-sci-java-a-bit-about-classpath","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/comp-sci-java-a-bit-about-classpath\/","title":{"rendered":"Comp Sci: Java: a bit about classpath"},"content":{"rendered":"\n<h2>Self-tutoring about Java: the tutor mentions classpath.<\/h2>\n<p>\nIt might properly be called CLASSPATH. It&#8217;s where Java will search for the class you want it to run.<\/p>\n<p>Yet, if you&#8217;re running a Java program from the command line after compiling it, you might get an error something like &#8220;Can&#8217;t find the main class [YourClass.class].&#8221; Why does such an error happen?<\/p>\n<p>Sometimes, a program that uses Java might have set your CLASSPATH without your knowning. Then, perhaps Java will look where the CLASSPATH points, rather than the current directory. This can be a confusing error to face when you&#8217;re in an unfamiliar environment.<\/p>\n<p>In Windows, one way around this seems to be to use the command line option -cp . when you go to run the program. Suppose, for instance, you&#8217;ve compiled P1 to the current directory and now want to run it:<\/p>\n<p style=\"font-family:monospace\">java -cp . P1<\/p>\n<p>might do the trick. <p style=\"font-family:monospace\">-cp .<\/p> tells java to &#8220;look in the current directory.&#8221; It&#8217;s worked for me when, for some reason, java couldn&#8217;t find the class it was supposed to run, yet was in the current directory.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/getStarted\/cupojava\/win32.html\">docs.oracle.com<\/a><\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/technotes\/tools\/windows\/classpath.html\">docs.oracle.com<\/a><\/p>\nJack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about Java: the tutor mentions classpath. It might properly be called CLASSPATH. It&#8217;s where Java will search for the class you want it to run. Yet, if you&#8217;re running a Java program from the command line after compiling it, &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/comp-sci-java-a-bit-about-classpath\/\"> <span class=\"screen-reader-text\">Comp Sci: Java: a bit about classpath<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1801],"tags":[],"class_list":["post-41928","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/41928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=41928"}],"version-history":[{"count":3,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/41928\/revisions"}],"predecessor-version":[{"id":41931,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/41928\/revisions\/41931"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=41928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=41928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=41928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}