English 中文(简体)
爪哇,如何启动几个罐子 使用1VM?
原标题:Java, how to start several jars that use 1 VM?

I want to run google closure compiler on many javascript files from python.
I use this:

subprocess.Popen( /usr/bin/java -jar /var/www/compiler.jar --js "%s" --js_output_file "%s"  % (fullname, dest_filename),shell=True);

But as I understand it creates java VM for each process.
So this eats all the RAM. I only can hear my hdd cracking as swap is being used. And system is almost hanged. Can I tell java somehow to use only 1 vm for all started processes?

可能是我写错东西了。那是因为我完全不知道java。对不起,因为

最佳回答

可能的答复1:

Google 关闭编译器确实接受多个输入文件,

java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js

这将只产生一个输出文件, 即所有输入的组合。 但如果您试图将每个文件单独编译, 这可能不是您想要的 。


可能的答复2:

使用 bash , python , 或您最喜欢的脚本语言)写一个小包装脚本将不难, 它会接受一对参数, 例如 。

wrapper.sh in1.js out1.js in2.js out2.js ...

wrapper.sh 中的代码可以绕过( pairs of) 参数,反复调用 java -java -jar --js=xxxxx --js_output_put_file=yyyy ,等待每个进程在开始下一个进程之前完成。这将有利于不平行启动每个进程, 因此至少您不会同时( 可能) 许多 JVMs 运行。 尽管您在每次运行时重新启动 JVM 方面有些效率不高 。


可能的答复3:

如果您 really 想要一个 JVM, 那么就无法在不写写一点 Java 代码( 据我所知) 的情况下按您的要求行事。 如果您熟悉 Java 代码 。 您可以复制 < a href=" http://code.google. com/ p/clocure-compiler/ source/browse/trunk/src/ com/google/javascrip/jscomp/CommandLineRunner.java " rel = " no folfoln noreferr" > CommandLineRunner.java 的源代码, 并修改该代码以适应您的需求 。

或者也许更简单些, 只要写一个小爪哇类, 其main 函数只是引用 Command>CCommandLineRunner 的任意次数, 通过适当的参数来模拟普通命令行的引用。 这里有快速和肮脏的东西可以做这个把戏 (>> titt to VonC )

import com.google.javascript.jscomp.CommandLineRunner;
import java.security.Permission;
public class MyRunner {
    public static void main(String [] args) {
        // Necessary since the closure compiler calls System.exit(...).
        System.setSecurityManager(new NoExitSecurityManager());
        for (int i=0; i<args.length; i+=2) {
            System.out.println("Compiling " + args[i] + " into " + args[i+1] + "...");
            try {
                CommandLineRunner.main(new String[] {
                    "--js=" + args[i],
                    "--js_output_file=" + args[i+1]
                });
            }
            catch (ExitException ee) {
                System.out.println("Finished with status: " + ee.getStatus());
            }
        }
    }

    private static class ExitException extends SecurityException {
        private int status;
        public ExitException(int status) { this.status = status; }
        public int getStatus() { return status; }
    }
    private static class NoExitSecurityManager extends SecurityManager {
        public void checkPermission(Permission p) { }
        public void checkPermission(Permission p, Object context) { }
        public void checkExit(int status) { throw new ExitException(status); }
    }
}

用类似的东西来编译它:

javac -classpath compiler.jar MyRunner.java

用像这样的东西运行它:

java -classpath .:compiler.jar MyRunner in1.js out1.js in2.js out2.js ...

看到这样的输出 :

Compiling in1.js into out1.js...
Finished with status: 0
Compiling in2.js into out2.js...
Finished with status: 0
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签