如果Windows Code Page是UTF-8,请尝试在Class Path中启动具有特殊字符的Java程序,请在ClassNotFoundException中产生

发布于 2025-02-09 04:27:16 字数 1156 浏览 1 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文