Java运行报错:无法找到或加载主类myRunningCode求助
Hey there, I’ve run into this exact snag before—let’s break it down and fix it quickly!
The Root Cause
When you compiled your code with javac -cp "/temp/package.jar" myRunningCode.java, the compiler generated myRunningCode.class right in your current working directory. But when you ran java -cp "/temp/package.jar" myRunningCode, you only told the JVM to look inside the package.jar file for classes—it had no clue to check your current folder where your compiled class lives.
The Fix
You need to add your current directory to the classpath so the JVM can locate your myRunningCode.class file. The syntax varies a bit by operating system:
- Linux/macOS: Use a colon (
:) to separate classpath entriesjava -cp ".:/temp/package.jar" myRunningCode - Windows: Use a semicolon (
;) instead (since colons are used for drive letters here)java -cp ".;/temp/package.jar" myRunningCode
Quick Note
The . in the classpath stands for your current working directory. By including it alongside the dependency jar, you’re telling the JVM: "Check both my current folder and the package.jar file to find all the classes I need to run this code."
内容的提问来源于stack exchange,提问作者Ques Ques

