How to determine build architecture (32bit / 64bit) with ant?
We have inherited an ant build file but now need to deploy to both 32bit and 64bit systems.
The non-Java bits are done with GNUMakefiles where we just call "uname" to get the info. Is there a similar or even easier way to mimic this with ant?
Asked by: Dainton811 | Posted: 23-01-2022
Answer 1
Late to the party, but what the heck...
${os.arch} only tells you if the JVM is 32/64bit. You may be running the 32bit JVM on a 64bit OS. Try this:
<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>
EDIT: As @GreenieMeanie pointed out, this requires the ant-contrib library from ant-contrib.sourceforge.net
Answered by: Briony563 | Posted: 24-02-2022Answer 2
you can get at the java system properties (http://java.sun.com/javase/6/docs/api/java/lang/System.html#getProperties()) from ant with ${os.arch}. other properties of interest might be os.name, os.version, sun.cpu.endian, and sun.arch.data.model.
Answered by: Abigail332 | Posted: 24-02-2022Answer 3
Here is an answer that works (I tested on Kubuntu 64, Debian 32, Windows 2000 and Windows XP) without the need of external or optional ANT dependencies. It was based on @phatypus's answer.
<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>
Answered by: Anna896 | Posted: 24-02-2022
Answer 4
You can just pass a parameter into the build file with the value you want. For example, if your target is dist
:
ant -Dbuild.target=32 dist
or
ant -Dbuild.target=64 dist
and then in your Ant build script, take different actions depending on the value of the ${build.target}
property (you can also use conditions to set a default value for the property if it is not set).
Or, you can check the value of the built-in system properties, such as ${os.arch}
.
Answer 5
os.arch does not work very well, another approach is asking the JVM, for example:
~$ 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
That'd have to be in a script or a wrapper.
Answered by: Adrian350 | Posted: 24-02-2022Answer 6
BTW, the os.arch (arch property of the os tag) I got for 64-bit Linux was amd64.
Answered by: Emma458 | Posted: 24-02-2022Answer 7
Assuming you are using ANT for building Java Application, Why would you need to know if it is a 32 bit arch or 64-bit? We can always pass parameters to ant tasks. A cleaner way would be to programmaticaly emit the system properties file used by Ant before calling the actual build. There is this interesting post http://forums.sun.com/thread.jspa?threadID=5306174.
Answered by: Chester849 | Posted: 24-02-2022Similar questions
java - How do I determine the optimal number of tasks to submit for my architecture?
I understand that for a CPU-bound task that you typically want 1 thread per core, otherwise you can start adding more threads per core. But what about tasks per thread (or are they one in the same)?
I'm trying to figure out how to chunk up a big problem into the optimal number of Runnables, so that I can submit them to an Executor. My understanding is that you can then configure t...
java - Determine JRE architecture 32-bit vs 64-bit
This question already has answers here:
dynamic - determine os architecture and bitness in java
I want to be able to dynamically determine the OS, architecture, and bit-ness in my Java application.
For example, I would like my application to know when it is on a Solaris 32-bit sparc machine or when it is on a x86 machine.
I know the system get property returns the arch of the JVM, but is there any to truly find out the real os arch and bit-ness?
Describe the architecture you use for Java web applications?
Closed. This question needs to be more focused. It ...
.NET equivalent of modern Java web architecture
Almost every new Java-web-project is using a modern MVC-framework such as Struts or Spring MVC for the web tier, Spring for the "Service"/business-logic-layer and an ORM mapper such as Hibernate for persistence. What is the equivalent in .NET?
I guess ASP.NET is used for the web tier and ADO.NET for persistence but what is the equivalent to Spring, i.e. what is used to wire transactions and components and such.
java - Architecture - Multiple web apps operating on the same data
I'm asking for a suitable architecture for the following Java web application:
The goal is to build several web applications which all operate on the same data. Suppose a banking system in which account data can be accessed by different web applications; it can be accessed by customers (online banking), by service personal (mostly read) and by the account administration department (admin tool). These applications ...
java - What architecture? Distribute content building across a cluster
I am building an content serving application composing of a cluster of two types of node, ContentServers and ContentBuilders.
The idea is to always serve fresh content. Content is fresh if it was built recently, i.e. Content.buildTime < MAX_AGE.
Requirements:
*ContentServers will only have to lookup content and serve it up (e.g. from a distributed cache or similar), no waiting for anything to be...
java - Space-based architecture?
One chapter in Pragmatic Programmer recommends looking at a blackboard/space-based architecture + a rules engine as a more flexible alternative to a traditional workflow system.
The project I'm working on currently uses a workflow engine, but I'd like to evaluate alternatives. I really feel like a SBA would be a better solution to our business problems, but I'm worried about a total lack of community support/user b...
java - Server architecture for a multiplayer game?
Performance of REST architecture for Java / C# messaging
I currently have an application that sends XML over TCP sockets from windows client to windows server.
We are rewriting the architecture and our servers are going to be in Java. One architecture we are looking at is a REST architecture over http. So C# WinForm clients will send info using this. We are looking for high throughput and low latency.
Does anyone have any performance metrics on this approach vers...
architecture - How do I organize my java packages in our web mvc project?
Do you have any good tips on how should i organize class packages for my java project?
We are usually building web MVC projects and our structure is something like this
com.company.project.model.* - all model classes
com.company.project.service.* - all service classes
com.company.project.service.entity.* - service classes related to particular model class
com.company.project.service.dao.* - dao classes
...
Java Application Architecture Guide
Is there a Java Application Architecture Guide that is a counterpart of this: http://www.codeplex.com/AppArchGuide ?
java - JVM garbage collection and a paging memory architecture
In the recent 10 year when discussing java and/or garbage collection, the only performance penalty that I have not been able to defend is that garbage collection algorithms more or less breaks when running in a paged memory architecture, and parts of the heap is getting paged out.
Unix systems (and especially Linux) agressively pages out memory that has not been touched for a while, and while that is good for your ...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)