E
E
Evgeny Ivanovich2015-07-11 16:51:47
Java
Evgeny Ivanovich, 2015-07-11 16:51:47

How to convert launch options correctly?

In general, there is a parameter
java -Djava.library.path=/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/natives -cp /home/linuz/qt-projects/build-launcher-Desktop-Debug /libraries/oshi-project/oshi-core/1.1/oshi-core-1.1.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/dev/jna/jna/ 3.4.0/jna-3.4.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/dev/jna/platform/3.4.0/platform-3.4.0 .jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar:/home/linuz /qt-projects/build-launcher-Desktop-Debug/libraries/net/sf/jopt-simple/jopt-simple/4.6/jopt-simple-4.6.jar:/home/linuz/qt-projects/build-launcher- Desktop-Debug/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/ libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar:/ home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries /io/netty/netty-all/4.0.23.Final/netty-all-4.0.23.Final.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/google/ guava/guava/17.0/guava-17.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3 .2.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar:/home/linuz/qt-projects/build- launcher-Desktop-Debug/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/jinput /jinput/2.0.5/jinput-2.0.5.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/jutils/jutils/1.0.0/juutils-1.0. 0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar:/home/linuz/ qt-projects/build-launcher-Desktop-Debug/libraries/com/mojang/authlib/1.5.21/authlib-1.5.21.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries /com/mojang/realms/1.7.21/realms-1.7.21.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar:/home/linuz/qt- projects/build-launcher-Desktop-Debug/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries /commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/httpcomponents/httpcore/ 4.3.2/httpcore-4.3.2.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api -2.0-beta9.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9. jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/lwjgl/lwjgl/lwjgl/2.9.4-nightly-20150209/lwjgl-2.9.4-nightly-20150209.jar:/home/ linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.4-nightly-20150209/lwjgl_util-2.9.4-nightly-20150209.jar:/home/linuz/qt -projects/build-launcher-Desktop-Debug/libraries/tv/twitch/twitch/6.5/twitch-6.5.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/ 1.8.7.jar net.minecraft.client.main.Main --accessToken null --version 1.8.7/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/1.8.7.jar net.minecraft.client.main.Main --accessToken null --version 1.8.7/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/1.8.7.jar net.minecraft.client.main.Main --accessToken null --version 1.8.7

The template for this parameter is
java -Djava.library.path={natives_path} -cp {classpath} net.minecraft.client.main.Main --accessToken null --version {version}

In principle, nothing complicated, just a fat classpath!
Dumped the JavaVM arguments.
I saw that the usual arguments go to sun.java.command, and {classpath} is specified in java.class.path, {native_path} in java.library.path.

Well, since everything is so simple, I do the following.

bool Jvm::launchJVM()
{
    jargs.clear();
    jargs.append("-Djava.library.path=/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/natives");
    jargs.append("-Djava.class.path=/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/oshi-project/oshi-core/1.1/oshi-core-1.1.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/dev/jna/platform/3.4.0/platform-3.4.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/ibm/icu/icu4j-core-mojang/51.2/icu4j-core-mojang-51.2.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/sf/jopt-simple/jopt-simple/4.6/jopt-simple-4.6.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/codecjorbis/20101023/codecjorbis-20101023.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/codecwav/20101023/codecwav-20101023.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/libraryjavasound/20101123/libraryjavasound-20101123.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/librarylwjglopenal/20100824/librarylwjglopenal-20100824.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/paulscode/soundsystem/20120107/soundsystem-20120107.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/io/netty/netty-all/4.0.23.Final/netty-all-4.0.23.Final.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/google/guava/guava/17.0/guava-17.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/commons-codec/commons-codec/1.9/commons-codec-1.9.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/jinput/jinput/2.0.5/jinput-2.0.5.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/net/java/jutils/jutils/1.0.0/jutils-1.0.0.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/mojang/authlib/1.5.21/authlib-1.5.21.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/com/mojang/realms/1.7.21/realms-1.7.21.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/httpcomponents/httpclient/4.3.3/httpclient-4.3.3.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/logging/log4j/log4j-api/2.0-beta9/log4j-api-2.0-beta9.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/apache/logging/log4j/log4j-core/2.0-beta9/log4j-core-2.0-beta9.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/lwjgl/lwjgl/lwjgl/2.9.4-nightly-20150209/lwjgl-2.9.4-nightly-20150209.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.4-nightly-20150209/lwjgl_util-2.9.4-nightly-20150209.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/libraries/tv/twitch/twitch/6.5/twitch-6.5.jar:/home/linuz/qt-projects/build-launcher-Desktop-Debug/versions/1.8.7/1.8.7.jar");
    jargs.append("-Dsun.java.command=net.minecraft.client.main.Main --accessToken null --version 1.8.7");
    jint alength = (jint)jargs.length();

    __debug_p("Args lenght" << alength);

    if(alength < 1)
    {
        __DEBUG_P("No java options");
        return false;
    }
    __DEBUG_P("Launching Java VM...");

    JavaVMOption options[alength];
    //jargs.setSharable(true);
    QByteArray *arrs = new QByteArray[alength];
    foreach(QString param, jargs)
    {
       static int i = 0;
       //options[i].optionString = param.toLatin1().data();
       //QByteArray arr = param.toLocal8Bit();
       arrs[i] = param.toLocal8Bit();

       char * pbuff = arrs[i].data();
       options[i].optionString = pbuff;
       //options[i].optionString = const_cast<char*>(param.toStdString().c_str());
       i++;
    }

    for(int i = 0; i < alength; i++)
    {
        qDebug() << "%$$%$%$%POINTER IN STRUCT" << options[i].optionString << endl;
    }

    JavaVMInitArgs vm_args;

   /* jint ret = JNI_GetDefaultJavaVMInitArgs(&vm_args);

    if(ret == JNI_ERR)
        __debug_p("Error while loading default jvm init args"); //*/

    vm_args.version = JNI_VERSION_1_6;
    vm_args.options = options;
    vm_args.nOptions = alength;
    vm_args.ignoreUnrecognized = JNI_FALSE;

    jint code = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    if(code == JNI_ERR)
    {
        __DEBUG_P("JVM is not runned, error code" << code);
        return false;
    }

    //__debug_p("Attaching" << jvm->AttachCurrentThreadAsDaemon((void**)&env, &vm_args));

    __DEBUG_P("JVM runned successful");

    emit JavaVMRunned(env);

    return true;
}

And it doesn't start! Something is wrong with these arguments -Dsun.java.command=net.minecraft.client.main.Main --accessToken null --version 1.8.7
Apparently they need to be specified differently, who knows? And can jvm logs be redirected to normal Qt output?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question