- 1 使用Eclipse编写代码
package com.zhiyuan.easy.coding;
/**
* @Description: This is my test
* @author: tobebetter9527
* @create: 2019-09-08 09:48
*/
public class Demo {
public static void main(String[] args) {
String str = System.getProperty("str");
if (str == null) {
System.out.println("str is null");
} else {
System.out.println("str=" + str);
}
}
}
- 2 找到文件,使用javac Demo.java编译文件
- 3 java -Dstr=hello运行代码
此时报找不到或无法加载主类的错误。
解决办法:
去掉类的包名,重新编译运行即可