개미로 빌드 아키텍처 (32 비트 / 64 비트)를 결정하는 방법은 무엇입니까?
문제
ANT 빌드 파일을 상속했지만 이제 32 비트 및 64 비트 시스템에 배포해야합니다.
비 자바 비트는 정보를 얻기 위해 "unam"이라고 부르는 gnumakefiles로 이루어집니다. 개미와 함께 이것을 모방하는 비슷하거나 더 쉬운 방법이 있습니까?
해결책
Java 시스템 속성을 얻을 수 있습니다 (http://java.sun.com/javase/6/docs/api/java/lang/system.html#getproperties ()) $ {os.arch}가있는 개미에서. 관심있는 다른 속성은 os.name, os.version, sun.cpu.endian 및 sun.arch.data.model입니다.
다른 팁
파티에 늦었지만 도대체 ...
$ {os.arch} JVM이 32/64 비트 인 경우에만 알려줍니다. 64 비트 OS에서 32 비트 JVM을 실행 중일 수 있습니다. 이 시도:
<var name ="os.bitness" value ="unknown"/>
<if>
<os family="windows"/>
<then>
<exec dir="." executable="cmd" outputproperty="command.ouput">
<arg line="/c SET ProgramFiles(x86)"/>
</exec>
<if>
<contains string="${command.ouput}" substring="Program Files (x86)"/>
<then>
<var name ="os.bitness" value ="64"/>
</then>
<else>
<var name ="os.bitness" value ="32"/>
</else>
</if>
</then>
<elseif>
<os family="unix"/>
<then>
<exec dir="." executable="/bin/sh" outputproperty="command.ouput">
<arg line="/c uname -m"/>
</exec>
<if>
<contains string="${command.ouput}" substring="_64"/>
<then>
<var name ="os.bitness" value ="64"/>
</then>
<else>
<var name ="os.bitness" value ="32"/>
</else>
</if>
</then>
</elseif>
</if>
<echo>OS bitness: ${os.bitness}</echo>
편집하다:@greeniemeanie가 지적했듯이, 이것은 Ant-Contrib.sourceforge.net의 Ant-Contrib 라이브러리가 필요합니다.
다음은 작동하는 답변입니다 (Kubuntu 64, Debian 32, Windows 2000 및 Windows XP에서 테스트했습니다) 없이 외부 또는 선택적 개미 종속성의 필요성. 그것은 @phatypus의 답변을 기반으로했습니다.
<project name="FindArchitecture" default="check-architecture" basedir=".">
<!-- Properties set: unix-like (if it is unix or linux), x64 (if it is 64-bits),
register- size (32 or 64) -->
<target name="check-architecture" depends="check-family,check-register" >
<echo>Register size: ${register-size}</echo>
<echo>OS Family: ${os-family}</echo>
</target>
<target name="check-family" >
<condition property="os-family" value="unix" else="windows">
<os family="unix" />
</condition>
<condition property="unix">
<os family="unix" />
</condition>
</target>
<target name="check-register" depends="reg-unix,reg-windows">
</target>
<!-- Test under GNU/Linux -->
<target name="reg-unix" if="unix">
<exec dir="." executable="uname" outputproperty="result">
<arg line="-m"/>
</exec>
<!-- String ends in 64 -->
<condition property="x64">
<matches string="${result}" pattern="^.*64$"/>
</condition>
<condition property="register-size" value="64" else="32">
<isset property="x64"/>
</condition>
</target>
<!-- Test under MS/Windows-->
<target name="reg-windows" unless="unix">
<!-- 64 bit Windows versions have the variable "ProgramFiles(x86)" -->
<exec dir="." executable="cmd" outputproperty="result">
<arg line="/c SET ProgramFiles(x86)"/>
</exec>
<!-- String ends in "Program Files (x86)" -->
<condition property="x64">
<matches string="${result}" pattern="^.*=.*Program Files \(x86\)"/>
</condition>
<condition property="register-size" value="64" else="32">
<isset property="x64"/>
</condition>
</target>
</project>
BTW, OS.Arch (OS 태그의 아치 속성) 64 비트 Linux에 대한 AMD64였습니다.
OS.Arch는 잘 작동하지 않으며 다른 접근 방식은 예를 들어 JVM을 묻습니다.
~$ java -d32 test Mon Jun 04 07:05:00 CEST 2007 ~$ echo $? 0 ~$ java -d64 test Running a 64-bit JVM is not supported on this platform. ~$ echo $? 1
그것은 대본이나 래퍼에 있어야합니다.
Java 애플리케이션을 구축하는 데 Ant를 사용하고 있다고 가정하면 32 비트 아치인지 64 비트인지 알아야하는 이유는 무엇입니까? 우리는 항상 ANT 작업에 매개 변수를 전달할 수 있습니다. 더 깨끗한 방법은 Programmaticaly가 실제 빌드를 호출하기 전에 Ant에서 사용하는 시스템 속성 파일을 방출하는 것입니다. 이 흥미로운 게시물이 있습니다 http://forums.sun.com/thread.jspa?threadid=5306174.