다음과 같이 새로운 OSVersion 클래스를 만들었습니다. 이 클래스에는 "IS_REDHAT_LINUX_7"변수가 있습니다.이 변수는 서버가 RHEL7 인 경우 true를 반환합니다.
참고 : - izpack의 일부로 제공되는 Osversion 클래스에는 RHEL의 버전을 확인하는 논리가 없으며 서버가 Rhel인지 아닌지 또는 기타 OS인지 여부를 확인하는 데만 사용할 수 있습니다.
<condition type="java" id="IS_REDHAT_LINUX_7">
<java>
<class>OsVersion</class>
<field>IS_REDHAT_LINUX_7</field>
</java>
<returnvalue type="boolean">true</returnvalue>
</condition>
이제 RHE7에 특정 작업을 수행하기 위해 ID = "IS_REDHAT_LINUX_7"를 사용할 수 있습니다 - : 아래 그림과 같이
public class OsVersion {
public final static String LINUX = "Linux";
public final static String REDHAT = "RedHat";
public final static String RED_HAT = "Red Hat";
public final static String OS_NAME = System.getProperty("os.name");
/**
* True if this is Linux.
*/
public static final boolean IS_LINUX = StringTool.startsWithIgnoreCase(OS_NAME, LINUX);
/**
* True if RedHat Linux was detected
*/
public static final boolean IS_REDHAT_LINUX = IS_LINUX && ((FileUtil.fileContains(getReleaseFileNamesList(), REDHAT)
|| FileUtil.fileContains(getReleaseFileNamesList(), RED_HAT)));
/**
* True if RHEL7 server.
*/
public static final boolean IS_REDHAT_LINUX_7 = IS_REDHAT_LINUX && ((getRedHatReleaseVersion() == 7));
/**
* True if RHEL6 server.
*/
public static final boolean IS_REDHAT_LINUX_6 = IS_REDHAT_LINUX && ((getRedHatReleaseVersion() == 6));
/**
* Gets the etc Release Filename
*
* @return name of the file the release info is stored in for Linux
* distributions
*/
private static String getReleaseFileName() {
String result = "";
File[] etcList = new File("/etc").listFiles();
if (etcList != null)
for (int idx = 0; idx < etcList.length; idx++) {
File etcEntry = etcList[idx];
if (etcEntry.isFile()) {
if (etcEntry.getName().endsWith("-release")) {
// match :-)
return result = etcEntry.toString();
}
}
}
return result;
}
/**
* Gets the list of etc Release Filenames
*
* @return name of the file the release info is stored in for Linux
* distributions
*/
private static List<String> getReleaseFileNamesList() {
List<String> result = new ArrayList<String>();
File[] etcList = new File("/etc").listFiles();
if (etcList != null)
for (int idx = 0; idx < etcList.length; idx++) {
File etcEntry = etcList[idx];
if (etcEntry.isFile()) {
if (etcEntry.getName().endsWith("redhat-release")) {
result.add(etcEntry.toString());
}
}
}
return result;
}
/**
* Gets the RedHat Release Version
*
* @return the major release version number
*/
private static Integer getRedHatReleaseVersion() {
String releaseDetails = "Red Hat Enterprise Linux Server release";
String relaseFile = getReleaseFileName();
BufferedReader br = null;
FileReader fr = null;
Integer redhatVersion = 0;
try {
fr = new FileReader(relaseFile);
br = new BufferedReader(fr);
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
if (sCurrentLine.trim().startsWith(releaseDetails)) {
String s[] = sCurrentLine.split("release");
char version = s[1].trim().charAt(0);
redhatVersion = Character.getNumericValue(version);
}
}
} catch (IOException e) {
//Do Nothing.
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return redhatVersion;
}
은 또한 지금은 새 조건을 만들어야합니다.