本文介绍了错误:无法访问 jarfile.编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题看似微不足道,但目前还没有找到解决办法.

C:UsersUser>"C:Program FilesJavajdk1.8.0_112injava" -jar "D:ValyaУчёбаТРПКнаумов_трпк_лаб2uildlibs
aumov_trpk_lab2-runnable.jar"错误:无法访问 jarfile D:Valya???????????????_????_???2uildlibs
aumov_trpk_lab2-runnable.jar

仅当我尝试访问位于具有非 ASCII 名称的目录中的 jar 时,才会出现此问题.当我在 Windows 7 上时,我 100% 确定我可以使用这样的路径运行 jar,但是自从我搬到 Win 10 之后,就没有运气了.引用路径没有帮助,-Dfile.encoding=UTF8 也是.

顺便说一句,如果我从 Intellij IDEA 点击 main 方法运行应用程序,我会收到以下错误.

"C:Program FilesJavajdk1.8.0_112injava" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.2.5in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_112jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_112jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_112jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_112jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_112jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_112jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_112jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_112jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_112jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_112jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_112jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_112jrelibjce.jar;C:Program FilesJavajdk1.8.0_112jrelibjfr.jar;C:Program FilesJavajdk1.8.0_112jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_112jrelibjsse.jar;C:Program FilesJavajdk1.8.0_112jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_112jrelibplugin.jar;C:Program FilesJavajdk1.8.0_112jrelib
esources.jar;C:Program FilesJavajdk1.8.0_112jrelib
t.jar;D:ValyaУчёбатест-кириллицыoutproductionтест-кириллицы;C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.2.5libidea_rt.jar"com.intellij.rt.execution.application.AppMain Main线程main"中的异常 java.lang.ClassNotFoundException: Main在 java.net.URLClassLoader.findClass(URLClassLoader.java:381)在 java.lang.ClassLoader.loadClass(ClassLoader.java:424)在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)在 java.lang.ClassLoader.loadClass(ClassLoader.java:357)在 java.lang.Class.forName0(本机方法)在 java.lang.Class.forName(Class.java:264)在 com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)

我的java版本是

java 版本1.8.0_112"Java(TM) SE 运行时环境 (build 1.8.0_112-b15)Java HotSpot(TM) 64 位服务器 VM(内部版本 25.112-b15,混合模式)

请随意询问任何其他信息,因为我不知道.

UPD我遇到问题的 Windows 的原始版本是安装了英语(美国)语言环境的 Win 10 LTSB.但是随着在 VM 上从头开始安装俄罗斯语言环境,问题就消失了.输出是:

C:UsersUserDocuments>java -jar наумов_тпрк_лаб2.jar错误:无效或损坏的 jarfile эрєьют_ЄяЁъ_ырс2.jar

是的,因为它是明文而损坏,但找到了路径,没有原始错误.不要让字母欺骗你,这不是 chcp 问题:虽然原始代码页是 866,但任何其他都让 java 找到文件的路径.

解决方案

首先,-Dfile.encoding=UTF8与文件名无关,而与

  • 然后点击更改位置...

  • 并设置正确的国家

  • 所以,它终于奏效了,但我希望有人提供有关此的详细信息.

    The problem seems trivial, but could not find a solution so far.

    C:UsersUser>"C:Program FilesJavajdk1.8.0_112injava" -jar "D:ValyaУчёбаТРПКнаумов_трпк_лаб2uildlibs
    aumov_trpk_lab2-runnable.jar"
    Error: Unable to access jarfile D:Valya???????????????_????_???2uildlibs
    aumov_trpk_lab2-runnable.jar
    

    The issue appears only when I try to access a jar that is sitting in a dir with non-ASCII name. I am 100% sure I could run jars with such a path when I was on Windows 7, but since I moved to Win 10, no luck. Quoting the path does not help, -Dfile.encoding=UTF8 also.

    BTW, if I run app from Intellij IDEA clicking on the main method, I get the following error.

    "C:Program FilesJavajdk1.8.0_112injava" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.2.5in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_112jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_112jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_112jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_112jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_112jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_112jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_112jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_112jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_112jrelibext
    ashorn.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_112jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_112jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_112jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_112jrelibjce.jar;C:Program FilesJavajdk1.8.0_112jrelibjfr.jar;C:Program FilesJavajdk1.8.0_112jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_112jrelibjsse.jar;C:Program FilesJavajdk1.8.0_112jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_112jrelibplugin.jar;C:Program FilesJavajdk1.8.0_112jrelib
    esources.jar;C:Program FilesJavajdk1.8.0_112jrelib
    t.jar;D:ValyaУчёбатест-кириллицыoutproductionтест-кириллицы;C:Program Files (x86)JetBrainsIntelliJ IDEA 2016.2.5libidea_rt.jar" com.intellij.rt.execution.application.AppMain Main
    Exception in thread "main" java.lang.ClassNotFoundException: Main
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
    

    My java version is

    java version "1.8.0_112"
    Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
    

    Feel free to ask for any additional info, cause I have just no clue.

    UPDThe original version of Windows, on which I had the issue is Win 10 LTSB installed with English (US) locale. But with the Russian locale installed from scratch on VM the problem is gone. And output is:

    C:UsersUserDocuments>java -jar наумов_тпрк_лаб2.jar
    Error: Invalid or corrupt jarfile эрєьют_ЄяЁъ_ырс2.jar
    

    Yes, corrupt because it's plaintext, but path is found, no original error. Don't let the letters fool you, that was not a chcp problem: although original codepage is 866, any other let java find path to the file.

    解决方案

    Firstly, -Dfile.encoding=UTF8 has nothing to do with filenames, but has something with filecontents.

    And the sweet part.

    1. Open start menu, type to find "Region & language settings".
    2. Go to Related settings.

    3. Then click on Change location...

    4. And set the proper country

    So, it finally works, but I hope someone provides details on this.

    这篇关于错误:无法访问 jarfile.编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    07-30 07:25