如果Windows Code Page是UTF-8,请尝试在Class Path中启动具有特殊字符的Java程序,请在ClassNotFoundException中产生
我正在尝试在C#中启动Java程序,其中包括中文。
ProcessStartInfo StartInfo = New ProcessStartInfo(Javaw);
StartInfo.Arguments = LaunchArgument; //-cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"
NewProcess.StartInfo = StartInfo;
NewProcess.Start();
如果Windows的代码页面是GBK(中文),这是正常的,但是如果代码页更改为UTF-8,Java将扔java.lang.classnotfoundfoundexception:com.something.test.test.test.test.test
当系统代码页面为UTF-8时,Java似乎无法在-CP
中正确读取中文字符。
我看到的传递命令行Unicode unicode to Java Code ,但似乎没有使用C#的解决方案。
修改系统代码页面很好,但是要求用户在使用软件之前调整系统设置很愚蠢...
我尝试过的内容:
添加
-dfile.encoding = gbk
或-dfile.encoding = utf-8
对参数。使用 *替换中文,但这也不起作用。
-cp“ d:\*\*。jar” com.something.test
- 。 >
chcp 936
"C:\Program Files\Java\jdk-17.0.3.1\bin\java.exe" -cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"
同样,由于用户的需求,无法在参数中避免这些汉字。对不起。
I am trying to launch a Java program in C# which arguments include Chinese.
ProcessStartInfo StartInfo = New ProcessStartInfo(Javaw);
StartInfo.Arguments = LaunchArgument; //-cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"
NewProcess.StartInfo = StartInfo;
NewProcess.Start();
This is normal if Windows's code page is GBK (Chinese), but if the code page is changed to UTF-8, Java will throw java.lang.ClassNotFoundException: com.something.test
In my examination, Java does not seem to be able to properly read Chinese characters in -cp
when the system code page is UTF-8.
I'v seen Passing command line unicode argument to Java code, but there doesn't seem to be a solution using C#.
Modifying the system code page is fine, but requiring users to adjust system settings before using the software is silly...
What I've tried:
Adding
-Dfile.encoding=GBK
or-Dfile.encoding=UTF-8
to the argument.Use * to replace Chinese like this, but that doesn't work either.
-cp "D:\*\*.jar" com.something.test
Use a .bat file and change the code page with the CHCP command at the beginning of it.
chcp 936
"C:\Program Files\Java\jdk-17.0.3.1\bin\java.exe" -cp "D:\特殊字符\文件名.jar" com.something.test --arg "特殊字符"
Also due to the needs of users, there is no way to avoid these Chinese characters in parameters. Sorry.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论