我需要在Linux,Solaris和Windows上的JRE 1.6中的os.arch屬性的所有可能值的最新編譯。 如果可能的話請引用你的發現的來源。 我需要這個值來選擇我的JNLP文件中的資源。基本上我需要根據JRE是32位還是64位來分配不同的JVM內存。 等待您的答案。 謝謝所有可能的值os.arch在32位JRE和64位Jre
回答
你也可以寫下如下代碼來找出os和它的archi。
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.SystemUtils;
public class PlatformDetection {
private String os;
private String arch;
public static String OS_WINDOWS = "windows";
public static String OS_OSX = "osx";
public static String OS_SOLARIS = "solaris";
public static String OS_LINUX = "linux";
public static String ARCH_PPC = "ppc";
public static String ARCH_X86_32 = "x86_32";
public static String ARCH_X86_64 = "x86_64";
public PlatformDetection() {
// resolve OS
if (SystemUtils.IS_OS_WINDOWS) {
this.os = OS_WINDOWS;
} else if (SystemUtils.IS_OS_MAC_OSX) {
this.os = OS_OSX;
} else if (SystemUtils.IS_OS_SOLARIS) {
this.os = OS_SOLARIS;
} else if (SystemUtils.IS_OS_LINUX) {
this.os = OS_LINUX;
} else {
throw new IllegalArgumentException("Unknown operating system " + SystemUtils.OS_NAME);
}
// resolve architecture
Map<String, String> archMap = new HashMap<String, String>();
archMap.put("x86", ARCH_X86_32);
archMap.put("i386", ARCH_X86_32);
archMap.put("i486", ARCH_X86_32);
archMap.put("i586", ARCH_X86_32);
archMap.put("i686", ARCH_X86_32);
archMap.put("x86_64", ARCH_X86_64);
archMap.put("amd64", ARCH_X86_64);
archMap.put("powerpc", ARCH_PPC);
this.arch = archMap.get(SystemUtils.OS_ARCH);
if (this.arch == null) {
throw new IllegalArgumentException("Unknown architecture " + SystemUtils.OS_ARCH);
}
}
public String getOs() {
return os;
}
public String getArch() {
return arch;
}
public void setArch(String arch) {
this.arch = arch;
}
public void setOs(String os) {
this.os = os;
}
public String toString() {
return os + "_" + arch;
}
}
請參閱下面的鏈接
在那裏你可以看看這個它在自己的JDK的最佳地點。
看好java.lang.System
可以看到的性質在initializeSystemClass
方法使用initProperties
方法,它依賴於本地代碼使用JNI
初始化:
private static native Properties initProperties(Properties props);
/**
* Initialize the system class. Called after thread initialization.
*/
private static void initializeSystemClass() {
// VM might invoke JNU_NewStringPlatform() to set those encoding
// sensitive properties (user.home, user.name, boot.class.path, etc.)
// during "props" initialization, in which it may need access, via
// System.getProperty(), to the related system encoding property that
// have been initialized (put into "props") at early stage of the
// initialization. So make sure the "props" is available at the
// very beginning of the initialization and all system properties to
// be put into it directly.
props = new Properties();
initProperties(props); // initialized by the VM
...
...
}
如果選中的這個原生代碼initProperties
呼籲源您可以在不同的平臺上查看os.arch
系統屬性的可能值。所以一步一步地做:
首先看System.c
看JNI
方法調用java.lang.System.initProperties
。從System.c
JNIEXPORT jobject JNICALL
Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
{
char buf[128];
java_props_t *sprops = GetJavaProperties(env);
jmethodID putID = (*env)->GetMethodID(env,
(*env)->GetObjectClass(env, props),
"put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
if (sprops == NULL || putID == NULL) return NULL;
PUTPROP(props, "java.specification.version",
JDK_MAJOR_VERSION "." JDK_MINOR_VERSION);
PUTPROP(props, "java.specification.name",
"Java Platform API Specification");
PUTPROP(props, "java.specification.vendor", "Sun Microsystems Inc.");
PUTPROP(props, "java.version", RELEASE);
PUTPROP(props, "java.vendor", VENDOR);
PUTPROP(props, "java.vendor.url", VENDOR_URL);
PUTPROP(props, "java.vendor.url.bug", VENDOR_URL_BUG);
...
/* os properties */
PUTPROP(props, "os.name", sprops->os_name);
PUTPROP(props, "os.version", sprops->os_version);
// HERE IS THE `os.arch` PROPERTY :)
PUTPROP(props, "os.arch", sprops->os_arch);
因此,大家可以看到os.arch
來自PUTPROP(props, "os.arch", sprops->os_arch);
和它的實現sprops
使用java_props_t *sprops = GetJavaProperties(env);
。所以讓我們來看看GetJavaProperties(env)
,這種方法是在java_props.h
定義爲:
java_props_t *GetJavaProperties(JNIEnv *env);
和實現似乎取決於操作系統。
所以最後看一下GetJavaProperties
的具體實現; 在Windows中,此屬性可能採取的值爲ia64
,amd64
,x86
或unknown
。您可以從java_props_md.c
file看到:
#if _M_IA64
sprops.os_arch = "ia64";
#elif _M_AMD64
sprops.os_arch = "amd64";
#elif _X86_
sprops.os_arch = "x86";
#else
sprops.os_arch = "unknown";
#endif
對於Solaris似乎更復雜,因爲在本地代碼的屬性值來自於具體定義用於Solaris作爲宏:
sprops.os_arch = ARCHPROPNAME;
而這個宏是在後續Makefile
定義爲:
OTHER_CPPFLAGS += -DARCHPROPNAME='"$(ARCHPROP)"'
所以看起來就像這個來自環境,編譯它的地方(對不起,我不是C專家,我只是在猜測,但也許我可以指導你)。
在src/linux/native/
的Linux文件夾中沒有java_props_md.c
,所以我想在這種情況下采取與solaris相同的來源(我再次猜測......)。
注意:我使用1.6版本來獲得這個值,但是新的值可以被添加到最新的java版本中,所以檢查你需要的版本。
希望它有幫助,
雖然這不是一個完整的解決方案,但我給了它的賞金,因爲你努力尋找規範值。注意:由於歷史原因,在jdk9之前的Java文件夾中,Solaris文件夾包含大部分通用的Unix資料,所以是的,該代碼將適用於Linux。如果價值來自環境,這很不幸,因爲這意味着它的價值是*開放式*。我希望有一個可能的價值整潔,規範的表格,而不需要迷信許多建築物的同義詞,但也許這是不可能的。 – Boann
@Boann感謝您對solaris和linux的確認。起初,我在查看文檔來查看'os.arch'的可能值,但似乎沒有關於它的官方信息......所以我直接看代碼;不幸的是,這也不能提供我們正在尋找的信息。無論如何,感謝賞金':)'。 – albciff
- 1. SWT在32位和64位JRE
- 2. 確定JRE架構32位和64位
- 3. 在java9下32和64位JRE
- 4. MXMLC和64位JRE
- 5. JNA調用與32位JRE但不與64位JRE
- 6. 如何檢測VC++代碼中的JRE位(32位或64位)
- 7. 在32位瀏覽器中檢測64位jre?
- 8. 如何在64位JRE中運行32位JAVA Applet MOC XOS
- 9. 強制Java applet運行在32位而不是64位JRE
- 10. 知道JRE是32位還是64位從Windows命令Promt
- 11. 如何獲得32位JRE路徑上64位Linux 64位瀏覽器和64位Java插件
- 12. 運行在64位JRE install4j在Win
- 13. 使罐子運行在32位jre
- 14. wget命令在32位JRE不工作
- 15. 32位和64位性能
- 16. 無法卸載Java JRE 1.7 32位
- 17. 如何檢測安裝哪種類型的JRE的 - 32位與64位
- 18. deployjava.getJREs不適用於Windows 7 64位jre
- 19. 32位和64位所有Windows平臺上的可移植性
- 20. C# - 在32位和64位
- 21. 在32位和64位
- 22. 如何訪問64位JNI lib中使用32位Java 8嵌入式JRE
- 23. 64位Java應用程序:是64位操作系統,64位JRE和64位應用程序嗎?
- 24. 從在32位jre上運行的桌面應用程序中調用使用64位jre的第三方API?可能嗎?
- 25. 32位和64位的ODP.NET
- 26. Sonarqube和Jenkins安裝在windows 64位 - 此時jre出乎意料
- 27. 64位debian和32位酒
- 28. ODBC .NET 32位和64位
- 29. Gluegen 32位和64位庫
- 30. Java 32位和64位
我沒有給這個答案的賞金,因爲它不清楚鏈接是多麼可靠。他們爲一些相同的體系結構(例如'powerpc' vs'ppc')檢測不同的'os.arch'值,他們是否知道這些值是否會出現或者是否是迷信編碼尚不清楚。你也在這裏複製粘貼其中一個,我不知道它的版權狀態是什麼。 – Boann