#Run a new instance of java application

44 messages · Page 1 of 1 (latest)

stiff spindle
#

I'm trying to run a new instance of my java application using the exec() function, that's my code:

String javaPath = System.getProperty("java.home");
      try {
         String path = System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw";
         String command = path + " -cp " + Minecraft.getInstance().gameDirectory.getAbsolutePath() + "\\versions\\myversion\\myversion.jar net.minecraft.client.main.Main " + Main.arguments.stream().map(Object::toString).collect(Collectors.joining(" "));
         LOGGER.info(command);
         Runtime.getRuntime().exec(command);
      } catch (IOException e) {
         e.printStackTrace();
      }```
I'm logging it, and it looks right:
```C:\Users\franc\AppData\Local\Packages\Microsoft.4297127D64EC6_8wekyb3d8bbwe\LocalCache\Local\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw -cp C:\Users\franc\AppData\Roaming\.minecraft\versions\myversion\myversion.jar net.minecraft.client.main.Main --username ZainJx --version myversion --gameDir C:\Users\franc\AppData\Roaming\.minecraft --assetsDir C:\Users\franc\AppData\Roaming\.minecraft\assets --assetIndex 3 --uuid 7ef0UUID7aafc22101f1 --accessToken alsdkjfhaTHELONGACCESSTOKENkasdjhff --clientId NDg1NzA2NjTHECLIENTIDMxNmNj --xuid 2UID543 --userType msa --versionType release```
i've also tried substituting `path` with `"java"` or `System.getProperty("java.home") + File.separator + "bin" + File.separator + "javaw.exe"`

The problem is that nothing happens. literally, nothing, no errors or anything, and the application doesn't run.
I'm open to any other method if this one won't work.
wintry dockBOT
#

This post has been reserved for your question.

Hey @stiff spindle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

supple tulip
stiff spindle
#

should I put it instead of the -cp?

supple tulip
#

-jar comes after the -cp part

#

syntax for the command is
javaw [options] -jar [jarfile] [programArguments]
options are things like cp or add-modules

stiff spindle
#

i was putting -cp because i thought it was to select my jar file, if i don't have to add any external library i can decide not to put -cp and put -jar [jarfile] [mainclass]?

supple tulip
#

or if you try to run the command manually in cmd is there an error ?

stiff spindle
#

i'm doing this but i get nothing

#

in cmd also nothing happens

supple tulip
#

yeah because running with javaw means that you don't attach to the process itself

#

try this instead:

BufferedReader r = new BufferedReader(new InputStreamReader(process.getErrorStream()));
            String line;
            while (true) {
                line = r.readLine();
                if (line == null) { break; }
                System.out.println(line);
            }
supple tulip
stiff spindle
#

so it doesn't find the main class.. but it is there

supple tulip
#

what does your manifest look like ?

stiff spindle
#
Main-Class: net.minecraft.client.main.Main```
supple tulip
#

It's not complaining that the main class wasn't found but that joptsimple/OptionSpec wasn't found ? What is that ?

stiff spindle
#

it's just for listing the arguments passed in the main function

#

so i have to include this

#

that's the problem okay

#

i import it as external library

supple tulip
#

and what happens if you try, instead of using -cp and defining your main class just running the jar using -jar

stiff spindle
#

same thing

supple tulip
#

the jar was exported as a runnable jar ?

stiff spindle
#

nop

supple tulip
#

that may be it. What ide are you using to create the jar ? Did it work in the ide ?

stiff spindle
#

i'm using intellijidea

#

i can't test on the ide, it's a complicated story let's not concentrate on this

supple tulip
#

did you use maven or gradle to built the jar ?

stiff spindle
#

i'm just running the build gradle task

#

( i get the jar in libs/)

supple tulip
#

are you sure gradle is packaging the required libraries inside the jar ?

stiff spindle
#

i'm not that sure now that i'm receiving this error, so probably not

#

i have all the jar files for my libraries, maybe i can link in my command an external library folder containings the jars

supple tulip
#

can you share your current build.gradle file

stiff spindle
#

why do you need it?

#

i'd prefere not to

supple tulip
#

Alright, I will just tell you what you have to do:
You want to add this line: id 'com.github.johnrengelman.shadow' version "7.1.2" to your plugins and add these lines

jar {
    manifest {
        attributes "Main-Class" : "org.example.Main"
    }
}

to the very end of your build.gradle file. Then build the jar using the task shadowJar.

stiff spindle
#

you're GREAT!!

#

Thank you, really

wintry dockBOT
# stiff spindle Thank you, really

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.