Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从java代码设置JRE变量_Java - Fatal编程技术网

从java代码设置JRE变量

从java代码设置JRE变量,java,Java,我们需要手动设置-Xmax和-Xmin环境变量,但我想从java代码中设置这些变量。有没有办法用java代码设置这些变量。?谢谢。您需要在运行的Java进程中设置这些设置吗?我认为那是不可能的。但是,您可以在调用Java程序的子进程上设置它们,例如通过 我得到了这个问题的解决方案:- public static void main(String[] args) { Properties prop = new Properties(); try { S

我们需要手动设置-Xmax和-Xmin环境变量,但我想从java代码中设置这些变量。有没有办法用java代码设置这些变量。?谢谢。

您需要在运行的Java进程中设置这些设置吗?我认为那是不可能的。但是,您可以在调用Java程序的子进程上设置它们,例如通过


我得到了这个问题的解决方案:-

     public static void main(String[] args) {
     Properties prop = new Properties();
     try {
        String path=System.getenv("APPDATA");
          path=path.substring(0,path.lastIndexOf('\\')+1)+"LocalLow\\Sun\\Java\\Deployment\\deployment.properties";
            System.err.println(path);

            prop.load(new FileInputStream(path));
            String jreIndex = null; 
            Enumeration enuKeys = prop.keys();
            while (enuKeys.hasMoreElements()) {
                String key = (String) enuKeys.nextElement();
                String value = prop.getProperty(key);
                if(value.contains("1.6.0_26")){
                    String[] st2 = key.split("\\.");  
                    if(st2.length==5){
                        jreIndex = st2[3];
                    }
                }
            }
            //SystemSettings SysConfigsettings = new SystemSettings();
            if(jreIndex != null){
            //  if (SysConfigsettings.getValue(SystemSettings.JRE_HEAP_SIZE))
              {
                prop.setProperty("deployment.javaws.jre."+jreIndex+".args", "-Xmx1024m");
              }
            }
            prop.store(new FileOutputStream(path), "UpdatedHeapSize");
            System.out.println("First : "+prop.getProperty("deployment.javaws.jre.0.args"));
    } catch (Exception e) {
        e.printStackTrace();
    }

}

“我们需要……”那么这是家庭作业吗?如果是这样,请贴上这样的标签。答案是否定的。我们指的是我和我的团队,这不是家庭作业。。我需要从应用程序GUI设置这些环境变量。
     public static void main(String[] args) {
     Properties prop = new Properties();
     try {
        String path=System.getenv("APPDATA");
          path=path.substring(0,path.lastIndexOf('\\')+1)+"LocalLow\\Sun\\Java\\Deployment\\deployment.properties";
            System.err.println(path);

            prop.load(new FileInputStream(path));
            String jreIndex = null; 
            Enumeration enuKeys = prop.keys();
            while (enuKeys.hasMoreElements()) {
                String key = (String) enuKeys.nextElement();
                String value = prop.getProperty(key);
                if(value.contains("1.6.0_26")){
                    String[] st2 = key.split("\\.");  
                    if(st2.length==5){
                        jreIndex = st2[3];
                    }
                }
            }
            //SystemSettings SysConfigsettings = new SystemSettings();
            if(jreIndex != null){
            //  if (SysConfigsettings.getValue(SystemSettings.JRE_HEAP_SIZE))
              {
                prop.setProperty("deployment.javaws.jre."+jreIndex+".args", "-Xmx1024m");
              }
            }
            prop.store(new FileOutputStream(path), "UpdatedHeapSize");
            System.out.println("First : "+prop.getProperty("deployment.javaws.jre.0.args"));
    } catch (Exception e) {
        e.printStackTrace();
    }