java -server xxxxxx 找不到或者无法加载主类

java -server xxxxxx 找不到或者无法加载主类

错误问题如下

PS C:\Users\Admin\Desktop\study-demo> java -server -Xms1024m -Xmx1024m -Duser.timezone=GMT+08 -Dfile.encoding=utf-8 -jar ./study-demo.jar --spring.config.location=./bootstrap.yml
错误: 找不到或无法加载主类 .timezone=GMT+08
原因: java.lang.ClassNotFoundException: /timezone=GMT+08
PS C:\Users\Admin\Desktop\study-demo>

解决问题过程

猜测是环境问题

Maven版本问题

本地Maven版本是3.3.9,升级到3.6.2后问题依旧,未解决问题;

Java环境问题

在执行应用启动脚本的窗口执行java,javac均正常回显,Java环境配置正确,未解决问题;

重新尝试执行命令

Shift + 鼠标右键 看到右键菜单中有两条吸引眼球的选项:

  • Git Bash Here
  • 在此处打开 Powershell 窗口(s)

好家伙,看到这里我似乎明白了,原来我的命令是在Powershell里面执行的呀!

重新尝试在Git Bash Here执行命令
Admin@DESKTOP-JO93RCG MINGW64 ~/Desktop/study-demo
$ java -server -Xms1024m -Xmx1024m -Duser.timezone=GMT+08 -Dfile.encoding=utf-8 -jar ./study-demo.jar --spring.config.location=./bootstrap.yml
Set logging system configuration path , using configuration from 'classpath:crisps-log.xml'
Set logging system configuration crisps.logging.gelf.facility , using configuration from 'ggy-inner-merchant'
Set logging output file , using file from [ INFO | ERROR | GELF | CONSOLE ]
Set logging output file , using file from [ INFO | ERROR | GELF | CONSOLE ]
............................................此处省略无用日志··...................................................................................
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                   服 务 启 动 成 功                              *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************

一切都在意料之中,此时此刻我是真的懂了;

解决方案

解决方案一

Shift + 鼠标右键 选择 在此处打开 Powershell 窗口(s) 并把命令做如下修改:

java -server -Xms1024m -Xmx1024m '-Duser.timezone=GMT+08' '-Dfile.encoding=utf-8' -jar ./study-demo.jar '--spring.config.location=./bootstrap.yml'
PS C:\Users\Admin\Desktop\study-demo> java -server -Xms1024m -Xmx1024m '-Duser.timezone=GMT+08' '-Dfile.encoding=utf-8' -jar ./study-demo.jar '--spring.config.location=./bootstrap.yml'
Set logging system configuration path , using configuration from 'classpath:crisps-log.xml'
Set logging system configuration crisps.logging.gelf.facility , using configuration from 'ggy-inner-merchant'
Set logging output file , using file from [ CONSOLE | INFO | ERROR | GELF ]
Set logging output file , using file from [ CONSOLE | INFO | ERROR | GELF ]
............................................此处省略无用日志··...................................................................................
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                   服 务 启 动 成 功                              *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************

解决方案二

Shift + 鼠标右键 选择 在此处打开 Powershell 窗口(s) 并在窗口中执行cmd命令,将Powershell切换回cmd;

PS C:\Users\Admin\Desktop\study-demo> cmd
Microsoft Windows [版本 10.0.19044.1348]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Admin\Desktop\study-demo>

如过前边的PS变为当前项目所在的盘符,则证明操作成功;

C:\Users\Admin\Desktop\study-demo> java -server -Xms1024m -Xmx1024m -Duser.timezone=GMT+08 -Dfile.encoding=utf-8 -jar ./study-demo.jar --spring.config.location=./bootstrap.yml
Set logging system configuration path , using configuration from 'classpath:crisps-log.xml'
Set logging system configuration crisps.logging.gelf.facility , using configuration from 'ggy-inner-merchant'
Set logging output file , using file from [ INFO | ERROR | GELF | CONSOLE ]
Set logging output file , using file from [ INFO | ERROR | GELF | CONSOLE ]
............................................此处省略无用日志··...................................................................................
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                   服 务 启 动 成 功                              *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *                                                                 *
2021-12-06 16:37:28.028  INFO 15920 - [main] n.d.q.i.StudyDemoApplication : *******************************************************************

至此问题已完美解决;

你可能感兴趣的:(那些年我踩过的坑,java,开发语言,后端)