17

I have a jar but I don't know if it is a .jar for a 64bit system or for a 32bit system. How to find that out?

EDIT: My .jar has native library dependency.

6
  • 6
    Why do you think it makes a difference? Unless there is native code in the .jar file it should not matter.
    – tehlexx
    Commented Sep 10, 2013 at 8:06
  • I think Jar file will not have that specific restriction for 32 / 64 bit. Commented Sep 10, 2013 at 8:10
  • 3
    If it did make a difference it would pretty much destroy the point of the java virtual machine; system independence Commented Sep 10, 2013 at 8:12
  • 8
    You need to unpack the *.so files and check their bitness with file Nothing else about the JAR will have bitness in it. Commented Sep 10, 2013 at 9:17
  • 6
    The title asks about the system where the jar was compiled (which as pointed out in comments and answers should be irrelevant), the question (and clarified in your comment) talks about native binaries stored inside the jar. That's a huge difference. Also, just as 32-bit and 32-bit may differ, so can 64-bit and 64-bit. It sounds like you are interested in the architecture and ABI of the native binaries (e.g. Linux x86-64, OpenBSD i386, FreeBSD sparc64, Windows 64-bit x86-like, ...), not the bitness per se.
    – user
    Commented Sep 10, 2013 at 11:07

3 Answers 3

40

Java bytecode is java bytecode, it doesn't matter whether it was built with a 32-bit or 64-bit JDK and there is no way to figure this out.

I think it does not make any difference to have a jar compiled with 32-bit or 64-bit. It should be machine-independent; unless you have some native library dependency or the java code is directly being compiled to native code.

5
  • That's exactly my case: I have native library dependencies.
    – Zhenya
    Commented Sep 10, 2013 at 8:56
  • In that case, I could suggest that each of the 32-bit jar and 64-bit jar should be bundled with corresponding version of native library and then program should be made to refer to right native library depending of the JRE version of the executing machine. Commented Sep 10, 2013 at 9:02
  • 2
    @Ievgen AFAIK that doesn't make much differences unless the native libraries are bundled inside the jar. See LWJGL, the native libraries are loaded at runtime.
    – Alvin Wong
    Commented Sep 10, 2013 at 9:07
  • 1
    @Ievgen You should include such important details in your question.
    – Uooo
    Commented Sep 10, 2013 at 11:29
  • @Uooo who doesn't have native dependencies ?
    – bvdb
    Commented Jul 30, 2018 at 9:26
16

A pure jar is not compiled to a particular architecture.

A 32 bit JVM will run the jar in 32 bit, likewise a 64 bt JVM will run the jar in 64 bit.

Of course, if your jar uses native libraries then the 'bitness' of these will have to match the JVM that you use to run the jar.

0
0

That's beauty of JVM and platform independence means. There is no value to 32bit or 64bit when it comes to Java, JVM, Jar etc.

3
  • This is not correct. As others mentioned there is no difference in the byte-code. But in the JVM there are differences. The 64-bit architecture uses more memory for the same data structures. This can result in longer GC pauses affecting application latency and so on...
    – Adrian B.
    Commented Sep 10, 2013 at 11:47
  • A JAR is not 32-bit or 64-bit, it can run on either JVM. However, a native shared library is either 32-bit or 64-bit and it can run only with a JVM with that bitness. This is a limitation of the way application run on Windows and Linux (and every other OS AFAIK) There is no way to load a 64-bit library on a 32-bit JVm or visa-versa. You need to match your sahred libraries versions with your JVM.
    – Rameez
    Commented Sep 10, 2013 at 11:55
  • @Eez not exactly a limitation of all systems, Afaik some can bundle code for different CPUs as a single binary.
    – josefx
    Commented Sep 15, 2013 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.