将程序的路径添加到环境变量并将其作为命令行命令

将程序的路径添加到环境变量并将其作为命令行命令

我使用gpj工具与智能卡读卡器通信。它工作正常。例如,当我想列出卡上的小程序时,我使用参数,-list并得到以下输出:

E:\RCII Projects Data\Smart Card\SOFT\gpj>gpj -list

E:\RCII Projects Data\Smart Card\SOFT\gpj>java -jar gpj.jar -list
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B xx xx xx xx xx xx xx xx xx 90 00

DEBUG: Command  APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 xx xx xx xx xx xx 90 0
0
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command  APDU: 80 50 00 00 08 81 E1 03 49 80 01 86 FC
DEBUG: Response APDU: 00 00 11 60 00 09 9A 5A 0A F9 FF 02 00 20 BA 9A 16 94 77 B
9 C6 B7 0D EF EC 38 1F 68 90 00
DEBUG: Command  APDU: 84 82 00 00 10 87 4A F3 C5 41 32 09 8F 44 EB 45 43 37 DC 5
6 91
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 84 82 00 00 08 87 4A F3 C5 41 32 09 8F
DEBUG: Response APDU: 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 80 00 02 4F 00
DEBUG: Response APDU: 08 A0 00 00 00 03 00 00 00 01 9E 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 06 xx xx xx xx xx xx xx 00 0E 63 61 6C 63 75 6C 61 74 6F 7
2 2E 61 70 70 07 00 xx xx xx xx xx xx xx xx xx 11 11 07 00 90 00
DEBUG: Command  APDU: 80 F2 40 00 02 4F 00
DEBUG: Response APDU: 06 xx xx xx xx xx xx xx xx xx xx 63 75 6C 61 74 6F 7
2 2E 61 70 70 07 xx xx xx xx xx xx xx xx xx 08 09 11 11 07 00 90 00
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 10 00 02 4F 00
DEBUG: Response APDU: 6A 81
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 07 A0 00 00 00 03 xx xx xx xx xx xx xx xx xx 03 10 01 00 0
5 31 50 41 59 2E 01 00 08 Dxx xx xx xx xx xx xx xx xx 00 08 D4 10 65 09 90 00 30
xx xx xx xx xx xx xx xx xx 00 05 D4 10 65 xx xx xx xx xx xx xx xx xx 00 04 10 01
 00 06 xx xx xx xx xx xx xx xx xx0 00 00 00 xx xx xx xx xx xx xx xx xx 55 0
1 00 xx xx xx xx xx xx xx xx xx 2E 70 xx xx xx xx xx xx xx xx xx 05 06
07 08 09 11 01 00 90 00
DEBUG: Command  APDU: 80 F2 20 00 02 4F 00
DEBUG: Response APDU: 07 A0 00 00 00 03 53 50 01 00 xx xx xx xx xx xx xx xx xx 0
5 31 50 41 59 2E 01 xx xx xx xx xx xx xx xx xx 08 D4 10 65 09 90 00 30
00 01 00 05 D4 10 xx xx xx xx xx xx xx xx xx 00 00 00 04 10 01
 00 06 xx xx xx xx xx xx xx xx xx 00 03 86 xx xx xx xx xx xx xx xx xx 0
1 00 xx xx xx xx xx xx xx xx xx 6B xx xx xx xx xx xx xx xx xx 06
07 08 09 11 01 00 90 00
AID: xx xx xx xx xx xx xx xx xx                       |........|        ISD LC: 1 P
R: 0x9E

AID: xx xx xx xx xx xx xx xx xx                             |."3DUf|          App LC: 7 P
R: 0x00

AID: 63 61 6C 63 75 6C 61 74 6F 72 2E 61 70 70     |calculator.app|  App LC: 7 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx              |...........|     App LC: 7 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                          |.....SP|         Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                            |......|          Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                               |1PAY.|           Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                       |..e.....|        Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                       |..e...0.|        Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                                |..e..|           Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                                |..e.0|           Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                             |......|          Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                             |....3.|          Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                          |.......|         Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx                               |."3DU|           Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx 70 61 63 6B  |calculator.pack| Exe LC: 1 P
R: 0x00

AID: xx xx xx xx xx xx xx xx xx 09 11                 |..........|      Exe LC: 1 P
R: 0x00

注:艾滋病是故意伪装的。

正如您上面看到的,我将gpj文件夹放在这个地址:E:\RCII Projects Data\Smart Card\SOFT\gpj

因为我想gpj在命令行的任何地方使用 cmd 命令,所以我将它的路径添加到我的 PATH 环境变量中。

现在,当我尝试列出小程序时,我收到以下输出。为什么?

D:\>gpj -list

D:\>java -jar gpj.jar -list
Error: Unable to access jarfile gpj.jar

D:\>

为什么我会收到错误?(以管理员身份运行已经检查但无效。)

请注意,它在其目录中仍能正常工作。

答案1

我认为您想要做的是修改\创建 CLASSPATH 环境变量。它的作用类似于 PATH,但适用于 Java 类和 jar 文件。顺便说一句,系统只会在 PATH 中查找 EXE\COM\BAT 文件;它永远不会找到 .jar 文件。完整描述如下:http://www3.ntu.edu.sg/home/ehchua/programming/howto/environment_variables.html

相关内容