Valya Valya - 21 days ago 7
Java Question

Error: Unable to access jarfile. Encoding issue

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

C:\Users\User>"C:\Program Files\Java\jdk1.8.0_112\bin\java" -jar "D:\Valya\Учёба\ТРПК\наумов_трпк_лаб2\build\libs\naumov_trpk_lab2-runnable.jar"
Error: Unable to access jarfile D:\Valya\?????\????\??????_????_???2\build\libs\naumov_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 Files\Java\jdk1.8.0_112\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_112\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_112\jre\lib\rt.jar;D:\Valya\Учёба\тест-кириллицы\out\production\тест-кириллицы;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.5\lib\idea_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.

UPD
The 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:\Users\User\Documents>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. Next, have to dump and diff the registry.

Answer

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. Related settings.

  3. Then click on Change location... Change location...

  4. And set the proper country And set the proper country

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

Comments