2017-01-22 4 views
2

ich ein einfaches Glas mit Hello.java haben:JAVA_TOOL_OPTIONS maximale Länge

class Hello { 
    public static void main(String[] a) { 
     System.out.println("Hello world!"); 
    } 
} 

Ich mag würde es einige Optionen über JAVA_TOOL_OPTIONS passieren. Wenn der Wert von $ JAVA_TOOL_OPTIONS Länge kleiner oder gleich 1024, wird aufgehoben:

$export JAVA_TOOL_OPTIONS=$(for i in {1..43}; do echo -n "-Dmyapp.opt${i}="123456789" "; done) 
$ echo $JAVA_TOOL_OPTIONS | wc -c 
1023 

java -jar hello.jar 
Picked up JAVA_TOOL_OPTIONS: -Dmyapp.opt1=123456789 -Dmyapp.opt2=123456789 -Dmyapp.opt3=123456789 -Dmyapp.opt4=123456789 -Dmyapp.opt5=123456789 -Dmyapp.opt6=123456789 -Dmyapp.opt7=123456789 -Dmyapp.opt8=123456789 -Dmyapp.opt9=123456789 -Dmyapp.opt10=123456789 -Dmyapp.opt11=123456789 -Dmyapp.opt12=123456789 -Dmyapp.opt13=123456789 -Dmyapp.opt14=123456789 -Dmyapp.opt15=123456789 -Dmyapp.opt16=123456789 -Dmyapp.opt17=123456789 -Dmyapp.opt18=123456789 -Dmyapp.opt19=123456789 -Dmyapp.opt20=123456789 -Dmyapp.opt21=123456789 -Dmyapp.opt22=123456789 -Dmyapp.opt23=123456789 -Dmyapp.opt24=123456789 -Dmyapp.opt25=123456789 -Dmyapp.opt26=123456789 -Dmyapp.opt27=123456789 -Dmyapp.opt28=123456789 -Dmyapp.opt29=123456789 -Dmyapp.opt30=123456789 -Dmyapp.opt31=123456789 -Dmyapp.opt32=123456789 -Dmyapp.opt33=123456789 -Dmyapp.opt34=123456789 -Dmyapp.opt35=123456789 -Dmyapp.opt36=123456789 -Dmyapp.opt37=123456789 -Dmyapp.opt38=123456789 -Dmyapp.opt39=123456789 -Dmyapp.opt40=123456789 -Dmyapp.opt41=123456789 -Dmyapp.opt42=123456789 -Dmyapp.opt43=123456789 
Hello world! 

Wenn der Wert von $ JAVA_TOOL_OPTIONS Länge von mehr als 1024 ist, wird es ignoriert:

$export JAVA_TOOL_OPTIONS+="$JAVA_TOOL_OPTIONS -Dmyapp.opt44=123456789" 
$ echo $JAVA_TOOL_OPTIONS | wc -c 
2070 

$ java -jar hello.jar 
Hello world! 

Wo von JAVA_TOOL_OPTIONS tut Zeichen Länge Grenze kommt von? Ist es möglich, die 1024 Zeichengrenze zu überschreiten?

+0

Siehe meine Antwort unten, warum es technisch passiert. Warum möchten Sie> 1024 Zeichen von JAVA_TOOL_OPTIONS weitergeben? Kannst du die '-D' Optionen nicht direkt an deinen' Java' Prozess übergeben? – dnswlt

+0

@dnswlt Ich schätze Ihre Hilfe! Die Anwendung wird im Docker-Container über das ENTRYPOINT-Skript gestartet. Das Skript (und Dockerfile) wird mit einer begrenzten Anzahl von Variablen bereitgestellt. Ich kann es nicht ändern und die -D-Optionen direkt übergeben. Der Provider empfiehlt die Verwendung von JAVA_TOOL_OPTIONS. Ich werde wahrscheinlich die Umgebungsvariable JAVA_OPT hinzufügen, da JAVA_TOOL_OPTIONS scheinbar Grenzen hat. – idobr

Antwort

4

Das ist eine interessante Frage! Wenn Sie den Quellcode des v7 OpenJDK überprüfen, insbesondere die command line argument parser, werden Sie sehen:

jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { 
    const int N_MAX_OPTIONS = 64; 
    const int OPTION_BUFFER_SIZE = 1024; 
    char buffer[OPTION_BUFFER_SIZE]; 

So ist die Puffergröße ist auf 1024 begrenzt, was genau dem entspricht, was Ihre schöne Experimente :-)

bestätigt

Ich weiß jedoch nicht und keine offizielle Dokumentation, warum dieses Limit existiert.

+0

Vielen Dank für die Recherche. Ich freue mich, Ihnen eine Prämie zu geben. – idobr