2014-04-09 2 views
0

이 질문을 검색하고 stackoverflow 자체에서 많은 일치 항목을 얻었지만 거기에있는 대답은 모순입니다.JAR (-Xmx)의 VM 옵션 설정 [JVM 시작 매개 변수]

Ques : How to add VM options to jar?에서 최고 득표 + 허용은 가능하지 않으며 Ques의 답변도 대부분이라고 말합니다. Can I set Java max heap size for running from a jar file? 아니요, 불가능합니다. "불가능한"이라는 답변의 대부분은 높은 평판을 가진 사람들에 의해 주어 졌으므로 우연히 모두 잘못 될 수는 없다고 생각합니다.

한 남자가 this 다른 사람이 그것을 위해 설치 프로그램을 만들거나 Launch4J를 사용하거나 배치 파일을 만들거나 다른 JAR을 만들고이를 통해 메인을 실행한다고 말하면서 할 수 있다고했지만 대부분이 많은 수를 얻지 못했습니다 "아니오"라고 말하는 사람들에 비해

정말 가능한가요? 내 문제는 내가 힙 공간이 부족하므로 JAR에서 그것을 늘리고 싶다.

1x. Netbeans에서 증가 된 힙 공간을 설정했습니다. JAR에서도 증가합니다. (나는 생각하지 않는다, 나는 단지 이것을 확인하고있다)

Q2. JAR에서 증가 된 힙 공간을 만들기 위해 지금해야 할 일은 무엇입니까? (배치 스크립팅에 대한 지식이 없기 때문에 쉽게 할 수있는 방법을 찾고 있는데 설치 관리자가이 파일을 배치하기 위해 이미 설치 프로그램을 설치하고 있기 때문에 추가 설치 프로그램을 설치하지 않으려 고합니다.) 간단한 탈출구가 있습니까?

답변

1

a1. Netbeans에서 응용 프로그램을 실행할 때 응용 프로그램을 실행하는 JVM 프로세스가 생성됩니다. Netbeans에서 힙 크기를 설정한다는 것은 단순히 사용자가 구성한 최대 힙 크기로 JVM을 시작 함을 의미합니다. 어떤 식 으로든 만드는 병에는 영향을주지 않습니다.

A2. 항아리 내에서 힙 크기를 구성 할 수 없습니다. 이것은 프로그래밍 방식으로 또는 일부 Manifest 구성으로 수행 할 수 없습니다.
최대 힙 설정은 JVM을 시작할 때 올바른 JVM 옵션을 전달해야 수행 할 수 있습니다.이 작업은 일종의 시작 스크립트를 사용하거나 stackoverflow의 여러 답변에서 언급 한 Java 시작 프로그램을 사용하여 수행 할 수 있습니다.
최종 사용자가 필요할 경우 메모리 설정을 제어 할 수 있으므로 시작 스크립트의 옵션이 더 좋습니다. 런처를 사용하면 메모리 설정이 일반적으로 하드 코딩되어 변경할 수 없습니다. 다양한 오픈 소스 Java 제품에 사용할 수있는 많은 시작 스크립트를 살펴 보시기 바랍니다. 또 다른 옵션은 "java startup script"또는 유사한 것을 검색하는 것입니다.

1

Q1. Netbeans에서 증가 된 힙 공간을 설정했습니다. JAR에서도 증가합니다.

The memroy use in JVM can be explain blow:

 


    
    init 
    represents the initial amount of memory (in bytes) that 
     the Java virtual machine requests from the operating system 
     for memory management during startup. The Java virtual machine 
     may request additional memory from the operating system and 
     may also release memory to the system over time. 
     The value of init may be undefined. 
    
    
    
    used 
    represents the amount of memory currently used (in bytes). 
    
    
    
    committed 
    represents the amount of memory (in bytes) that is 
     guaranteed to be available for use by the Java virtual machine. 
     The amount of committed memory may change over time (increase 
     or decrease). The Java virtual machine may release memory to 
     the system and committed could be less than init. 
     committed will always be greater than 
     or equal to used. 
    
    
    
    max 
    represents the maximum amount of memory (in bytes) 
     that can be used for memory management. Its value may be undefined. 
     The maximum amount of memory may change over time if defined. 
     The amount of used and committed memory will always be less than 
     or equal to max if max is defined. 
     A memory allocation may fail if it attempts to increase the 
     used memory such that used > committed even 
     if used <= max would still be true (for example, 
     when the system is low on virtual memory). 
    
    
    

Q2. JAR에서 증가 된 힙 공간을 만들기 위해 지금해야 할 일은 무엇입니까?

다른 병에서 항아리 포장과 같은 몇 가지 트릭으로이 작업을 수행 할 수 있습니다.

another_project/resources /에 jar 파일을 복사하고 another_project를 jar 파일로 패키징하십시오.

코드 타격은 예제 일 뿐이며 실행 또는 컴파일 할 수 없습니다.

public static void main(String[] args) { 
    String jarFile = this.getClass().getResource("/resources/you.jar").getFile(); 
    Runtime.getRuntime().exec("java -Xmx256m -jar "+jarFile); 
}