简体   繁体   English

运行Java bat文件时出错

[英]Error when running java bat file

When i am starting my bat file: 当我启动蝙蝠文件时:

@echo off
title x
:start
echo.
java -server -Dfile.encoding=UTF-8 -Xms64m -Xmx64m -Xbootclasspath/p:../libs/l2ft.jar -    cp config/xml;../libs/*; l2ft.loginserver.AuthServer
if ERRORLEVEL 2 goto restart
if ERRORLEVEL 1 goto error
goto end
:restart
echo Restarted ...
goto start
:error
echo Terminated abnormaly ...
:end
echo Terminated ...

I am getting strange error: 我收到奇怪的错误:

Error occurred during initialization of VM
java.nio.charset.UnsupportedCharsetException: UTF-8
    at java.nio.charset.Charset.forName(Unknown Source)
    at java.nio.charset.Charset.defaultCharset(Unknown Source)
    at sun.nio.cs.StreamEncoder.forOutputStreamWriter(Unknown Source)
    at java.io.OutputStreamWriter.<init>(Unknown Source)
    at java.io.PrintStream.<init>(Unknown Source)
    at java.io.PrintStream.<init>(Unknown Source)
    at java.lang.System.initializeSystemClass(Unknown Source)

I have tried to reinstall java jdk, i have got default encoding in bat file already: -Dfile.encoding=UTF-8, so i dont know whats the solution for the problem. 我试图重新安装java jdk,我已经在bat文件中有了默认编码:-Dfile.encoding = UTF-8,所以我不知道该问题的解决方案。

I found the solution. 我找到了解决方案。 In the jar that contained AuthServer, were a lot of russian characters that UTF-8 doesnt support. 在包含AuthServer的jar中,UTF-8不支持许多俄语字符。 After removing each of those characters and recompiling, problem was gone. 删除每个字符并重新编译后,问题就消失了。 Jar file of my friend also contained those characters, but it was working without a problems. 我朋友的jar文件也包含这些字符,但是它可以正常工作。 I dont know how, but thats not important now, since the problem is gone. 我不知道如何,但是现在不重要了,因为问题已经解决了。

It looks like your Java doesn't support UTF-8, which is really strange, because every Java should support it according to the documentation of the Charset class . 看来您的Java不支持UTF-8,这确实很奇怪,因为每个Java都应该根据Charset类文档来支持它。

Try to run this code to make sure that UTF-8 is really not supported. 尝试运行此代码,以确保确实不支持UTF-8。

import java.nio.charset.Charset;

public class TestCharset {
    public static void main(String[] args) {
        System.out.println(Charset.forName("UTF-8"));
    }
}

If UTF-8 is not supported, it should throw an exception. 如果不支持UTF-8,则应引发异常。

You may also try it with UTF8 instead of UTF-8 just in case your use an incorrect hyphen character. 您也可以使用UTF8而不是UTF-8尝试,以防万一您使用了不正确的连字符。 UTF-8 is correct according to the specs, but UTF8 works on my machine as well. 根据规格, UTF-8是正确的,但是UTF8可以在我的机器上使用。

I am not sure about your p:../libs/l2ft.jar, that is not a right path. 我不确定您的p:../ libs / l2ft.jar,这不是正确的路径。 Try to replace your current line with this: 尝试以此替换当前行:

java -server -Dfile.encoding=UTF-8 -Xms64m -Xmx64m -cp p:../libs/l2ft.jar;config/xml;../libs/* l2ft.loginserver.AuthServer

just be sure to replace "p:../libs/l2ft.jar" with a proper path where the l2ft.jar resides. 只要确保将“ p:../ libs / l2ft.jar”替换为l2ft.jar所在的正确路径即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM