再次证实了 classpath 的设置有多么重要, 错误的值最明显的引起报错就是错误: 找不到或无法加载主类 HmacTestEasy2
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>java -cp %CLASSPATH%;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okhttp3\okhttp\3.10.0\okhttp-3.10.0.jar;C:\runtime-ee-2.0_09000\work\nar\extensions\nifi-hwx-schema-registry-nar-1.7.1-2.0_09000.nar-unpacked\META-INF\bundled-dependencies\commons-lang3-3.4.jar;G:\Projects\github\hmac-auth-java-sdk\hmac-auth\target\hmac-auth-1.0-SNAPSHOT.jar;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okio\okio\1.14.0\okio-1.14.0.jar HmacTestEasy2
错误: 找不到或无法加载主类 HmacTestEasy2
一直无法解释为何报上面的错误呢?编译都OK啊?!
查看下当前环境变量配置
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>echo %CLASSPATH%
%CLASSPATH%
G:\Projects\github\hmac-auth-java-sdk\hmac-auth> %CLASSPATH%
'%CLASSPATH%' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>print %CLASSPATH%
找不到文件 %CLASSPATH%
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>echo %JAVA_HOME%
F:\Java\jdk1.8.0_102
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>echo %CLASSPATH%
%CLASSPATH%
天哪,CLASSPATH变量啥时候没有任何值的?!
我的windows不是很早之前就配置好了各个java环境变量吗?!
在java
命令的-cp
参数的值后面追加;./
吧,执行成功?!
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>java -cp %CLASSPATH%;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okhttp3\okhttp\3.10.0\okhttp-3.10.0.jar;C:\runtime-ee-2.0_09000\work\nar\extensions\nifi-hwx-schema-registry-nar-1.7.1-2.0_09000.nar-unpacked\META-INF\bundled-dependencies\commons-lang3-3.4.jar;G:\Projects\github\hmac-auth-java-sdk\hmac-auth\target\hmac-auth-1.0-SNAPSHOT.jar;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okio\okio\1.14.0\okio-1.14.0.jar;./ HmacTestEasy2
X-Date: Tue, 30 Jun 2020 04:16:40 GMT
Content-md5: Xyt1XD8MNZHo0CqYKWINnA==
Authorization: hmac username="1533661890@qq.com",algorithm="hmac-sha256",headers="X-Date Content-md5 request-line",signature="mZDCV0gfCpJec5ggcIi7JyzEBjwLTOs0jE1Yp3iaMmU="
Response Code: 200
Response Body: {"code":200102,"message":"查询数据成功","currentPageNum":1,"totalpage":4,"data":[{"app":"392500662","logTimestamp":"2020-03-05 23:11:57.5310000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:12:07.8080000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:12:57.5370000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:13:21.9730000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:14:24.0070000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:19:14.7320000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:19:53.6760000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:40:13.0110000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-06 09:42:49.7440000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-06 09:43:13.0940000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"}]}
再次去掉在java
命令的-cp
参数的值后面追加的;./
,问题复现了吧!
G:\Projects\github\hmac-auth-java-sdk\hmac-auth>java -cp %CLASSPATH%;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okhttp3\okhttp\3.10.0\okhttp-3.10.0.jar;C:\runtime-ee-2.0_09000\work\nar\extensions\nifi-hwx-schema-registry-nar-1.7.1-2.0_09000.nar-unpacked\META-INF\bundled-dependencies\commons-lang3-3.4.jar;G:\Projects\github\hmac-auth-java-sdk\hmac-auth\target\hmac-auth-1.0-SNAPSHOT.jar;E:\EclipseWorkspace_Maven\MavenSetting\HelloMaven\repo\com\squareup\okio\okio\1.14.0\okio-1.14.0.jar;./ HmacTestEasy2ll
错误: 找不到或无法加载主类 HmacTestEasy2ll
原来我的windows下的CLASSPATH环境变量之前被删除了, 命令行下执行时,又没有指定./
当前目录到classpath, 所以一直找不到 主类
啊?!
天哪,我以前都是会把当前路径写入到windows系统的CLASSPATH
变量的!
而且,在windows上,不是一直说CLASSPATH类似于PATH吗?
windows上的PATH就会默认搜索当前目录下的匹配的可执行文件嘛!
以前小伙伴们在一起,不也是说windows下的CLASSPATH在命令行下使用不用显示包括当前目录么?
结果今天就被坑的稀里糊涂!
网友评论