Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Default JVM arguments for a particular jar?  (Read 1843 times)
0 Members and 1 Guest are viewing this topic.
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Posted 2014-03-26 19:32:49 »

Quick question:  Is there a way to make my executable jar file run with certain jvm arguments by default?  I don't mean by tweaking my current vm, I mean having the arguments be there by default for a specific jar.  That way, I could maybe run the concurrent mark and sweep algorithm for my game jar, and not some other jar.  Haven't been able to find anything in a google search.  I know Minecraft lets you do this, but Minecraft first opens a launcher before firing up the jvm, and the launcher is a native executable.

Specifically, I want to pass -XX:+UseConcMarkSweepGC by default.

Did you know that 90% of statistics are wrong?
Online Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2014-03-26 19:35:01 »

You can't. Emo

If making an exe is not your thing, create a batch file instead.
   (and on Windows, turn that into an exe with bat-to-exe)


If you really want a double-clickable jar (bad idea, but whatyagonnado), you can spawn a new java process with the proper VM args.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #2 - Posted 2014-03-26 19:37:59 »

Shameless self-promotion: I just released a tool called SvgExe that supports exactly this.

Edit: Here is the JGO announcement thread.

Static Void Games - Play indie games, learn game programming, upload your own games!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #3 - Posted 2014-03-26 20:25:03 »

This does what I want, as it turns out.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
package main;
import java.io.IOException;
import javax.swing.JOptionPane;


/**
 * Class that fires an external jar
 * @author William Andrew Cahill
 */

public class Main2
{
   /**
    * Main method that fires an external jar
    * @param args Derp :)
    */

   public static void main(String[] args)
   {
      try
      {
         Runtime.getRuntime().exec("java -jar -XX:+UseConcMarkSweepGC jarlie.jar");
      }
      catch (IOException e)
      {
         JOptionPane.showMessageDialog(null, "Oh noes!");
      }
   }
}


Edit:  I run a jar that runs another jar, in case this isn't obvious.  No batch files for me!

Did you know that 90% of statistics are wrong?
Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #4 - Posted 2014-03-26 21:04:51 »

That'll work, until the user renames the jar! :p

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #5 - Posted 2014-03-26 21:45:16 »

Users are weirdos.  Why would they want to do that?  Actually, I just thought of something...  Are the commands I typed windows specific?

Did you know that 90% of statistics are wrong?
Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #6 - Posted 2014-03-26 21:52:24 »

I don't think anything you have above is Windows-specific.

And there is a way to get the name of the jar being executed, if that's the way you want to go.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #7 - Posted 2014-03-26 23:18:36 »

Oh!  You're talking about programming users.  This was just an example!  No need to do anything too fancy.  Just replace "jarlie.jar" with something more... suitable...

Did you know that 90% of statistics are wrong?
Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #8 - Posted 2014-03-26 23:25:34 »

No I meant your end users, you know how misbehaved they can be!

This is what I use:

File jarFile = new File(SomeClass.class.getProtectionDomain().getCodeSource().getLocation().getPath());
String fullJarPath = jarFile.getAbsolutePath();

Static Void Games - Play indie games, learn game programming, upload your own games!
Online Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2014-03-27 00:00:52 »

Any game will break when users start renaming files. Don't waste time on it.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #10 - Posted 2014-03-27 00:06:36 »

Any game will break when users start renaming files. Don't waste time on it.

Sure, if they rename internal files you're out of luck. But I'm talking about renaming a single runnable file, which is probably pretty common.

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #11 - Posted 2014-03-27 03:22:07 »

Here's an example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
import java.io.IOException;
import java.net.URISyntaxException;

public class Main
{
    public static void doMain()
    {
        // Run the application.
       System.out.println("Hello World");
    }
   
    public static void main(String[] args)
    {
        for(String s : args)
        {
            if(s.equals("run"))
            {
                doMain();
                return;
            }
        }
       
        try
        {
            ProcessBuilder pb = new ProcessBuilder();
            pb.command("java", "-jar", Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(), "run");
            pb.inheritIO();
            pb.start();
            System.exit(0);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        catch(URISyntaxException e)
        {
            e.printStackTrace();
        }
    }
}


Simply add any commands you want to the ProcessBuilder, move your current main function to doMain(), and you're set.

Edit: Remember in your IDE to add 'run' to the application arguments.

Online princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #12 - Posted 2014-03-27 10:33:31 »

Any game will break when users start renaming files. Don't waste time on it.

Sure, if they rename internal files you're out of luck. But I'm talking about renaming a single runnable file, which is probably pretty common.
I've never heard of anyone doing that, and I've been surrounded by idiots for years.

Cas Smiley

Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #13 - Posted 2014-03-27 12:30:49 »

Any game will break when users start renaming files. Don't waste time on it.

Sure, if they rename internal files you're out of luck. But I'm talking about renaming a single runnable file, which is probably pretty common.
I've never heard of anyone doing that, and I've been surrounded by idiots for years.

Cas Smiley

I think I'm probably being unclear. I think what the OP is talking about is creating a single runnable .jar file that users can download. I can see a situation where, for example, a new version of the jar is released, and the user downloads it to the same place as the old one. The OS will probably append a (2) or something to the jar, or the jar will contain _v1.2.3 in the name. The user might think that's ugly and just want to have Game.jar somewhere, so he renames it. I'm not talking about getting into the internal files of the game, just the main shortcut that the user is actually going to use. It seems like a common enough case to worry about, especially since it's a one line fix!

Although this is all happening in theoretical land and the OP's code was just an example anyway, so I'm probably just being pedantic.

Static Void Games - Play indie games, learn game programming, upload your own games!
Online princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2014-03-27 13:03:32 »

Relying on double-clicking jars is not wise anyway; I seem to recall it's been turned off by default (somebody know for sure?) because it's a bit of a security issue, bypassing all the OS security features for running downloadable executables.

Cas Smiley

Offline KevinWorkman

JGO Wizard


Medals: 51
Projects: 11
Exp: 12 years


klaatu barada nikto


« Reply #15 - Posted 2014-03-27 14:59:49 »

Relying on double-clicking jars is not wise anyway; I seem to recall it's been turned off by default (somebody know for sure?) because it's a bit of a security issue, bypassing all the OS security features for running downloadable executables.

Cas Smiley

Eh, I was just responding to the OP, which I think was talking about runnable jars. Double-clicking jars still works for me on the latest Windows 8. Do you know what OS double-clicking has been deactivated for? If that's true, that's a pretty big deal...

Static Void Games - Play indie games, learn game programming, upload your own games!
Offline DrewLols

Senior Member


Medals: 1
Projects: 1


Noob going through metamorphosis...


« Reply #16 - Posted 2014-03-28 18:00:41 »

Any game will break when users start renaming files. Don't waste time on it.

Sure, if they rename internal files you're out of luck. But I'm talking about renaming a single runnable file, which is probably pretty common.
I've never heard of anyone doing that, and I've been surrounded by idiots for years.

Cas Smiley

I think I'm probably being unclear. I think what the OP is talking about is creating a single runnable .jar file that users can download. I can see a situation where, for example, a new version of the jar is released, and the user downloads it to the same place as the old one. The OS will probably append a (2) or something to the jar, or the jar will contain _v1.2.3 in the name. The user might think that's ugly and just want to have Game.jar somewhere, so he renames it. I'm not talking about getting into the internal files of the game, just the main shortcut that the user is actually going to use. It seems like a common enough case to worry about, especially since it's a one line fix!

Although this is all happening in theoretical land and the OP's code was just an example anyway, so I'm probably just being pedantic.

I'm mostly just writing this code for myself.  I'm not so noble as to write this code to make someone ELSE's life easier!  What kind of guy do you think I am?  xD  Yes, this is for my own purposes in the event that I want to make a particular game that runs with certain JVM arguments.  In my opinion, there should be a file in the jar that lets you specify this instead of doing this crazy indirection.  Even worse is having the user fire up a jar from the command line.  No everyday user should have to do that anymore!

Did you know that 90% of statistics are wrong?
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #17 - Posted 2014-03-28 21:27:53 »

The code I provided does all the crazy indirection needed, and should run fine from double-clicking.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!