Antでビルドアーキテクチャ(32ビット/ 64ビット)を決定する方法は?
質問
antビルドファイルを継承しましたが、32ビットシステムと64ビットシステムの両方に展開する必要があります。
Java以外の部分はGNUMakefilesで行われますが、ここでは" uname"を呼び出すだけです。情報を取得します。アリでこれを模倣する同様の、またはさらに簡単な方法はありますか?
解決
Javaシステムプロパティで取得できます( http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties())から$ {os.arch}を使用してantから。関心のある他のプロパティは、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でテストしました)外部またはオプションのANT依存関係を必要とせずに 。 @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<*>quot;/>
</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>
BETWEEN、os.arch(osタグのarchプロパティ)は、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
スクリプトまたはラッパーに含まれている必要があります。
ANTを使用してJavaアプリケーションを構築している場合、32ビットアーチか64ビットかを知る必要があるのはなぜですか?いつでもパラメーターをantタスクに渡すことができます。よりクリーンな方法は、実際のビルドを呼び出す前に、Antが使用するシステムプロパティファイルをプログラムで発行することです。この興味深い投稿があります http://forums.sun.com/thread.jspa?threadID = 5306174 。