Can java JDK be portable? - java

My java programs are stored in my flash drive.
I just want to know if it is possible to store the JDK in the flash drive so that I can compile and run my programs at any computer (i.e., portable).
Thanks in advance.

The JDK itself is a compiled application. You can define JAVA_HOME to point to your JDK wherever you want, to force compilation. However, you can't take a 64 bit JDK and run it on a 32 bit Windows machine, and likewise you can't take the Windows version and run it on Mac or Linux, so no it's not portable.

Related

java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM in windows

I am developing a windows application.
I need to create an installer(a common installer for both 32 bit and 64 bit windows OS) for that, for that I am using Install4J software.
I developed in Windows 32 bit, jdk 1.7.
Installer working fine in 32 bit windows os, but when I try to create installer in win 64 bit os, it is throwing me an error like java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
Please help to sort out this..
The problem is that there are separate "swt.jar" files for 32bit and 64bit Windows JVMs, and they are not interchangeable. You can't use the 32bit Windows JAR on a 64bit Windows JVM ... or the other way around. (AFAIK, the fundamental impediment is in Windows and the JVM rather than SWT.)
One possibility is to do some classloader tricks, and dynamically choose between different JARs depending on the platform that your app detects at runtime. The installer would need incorporate both flavours of the SWT JAR ... with different names.
This answer goes into more detail: Supporting SWT on Windows/Mac & 32bit/64bit
Well that is just because when u install program into the Program files that will install only 32-but and will load 32-bit libraries so u can do one thing very simple solution of that just install your program in the the Program files x86 if u have 64 bit system.
that work for me and might work for u too.

Compile 32 bit Java builds on 64 bit machine with Eclipse

so the questions as in the title, I need to run my server application in Tomcat on a System which is 32 bit Windows XP, I am working and compiling on my 64 bit Windows 7 in Eclipse. How do I compile it to 32 bit, what do I need to do? I assume it won't work on the 32 bit Windows when I'm compiling it on a 64 bit machine?
Java doesn't build 32-bit or 64-bit applications - bytecode is portable across different bit architectures.
The only exception is native libraries that you might be using in your code. If there are any then you will have to manually compile those for the respective platform. Otherwise the java code is totally portable across 32-bit and 64-bit platforms.
The problem is your JNI DLL, which needs to be compiled for 32-bit to match the 32-bit JRE.
Java is independent of the OS.
You can compile with your 64bit machine and run this on a 32bit computer as long as this computer has a 32bit VM.
If you're still searching for some "simple" solution, one would be to install a 32 bit os in a virtual machine and run eclipse from there.. Very ugly I know, but it works.
Another approach is mentioned here. How to launch java swing app which used precompled DLL from cmd?
You could install a 32bits jdk on a 64bits machine. point the JAVA_HOME to this jdk and use it. It

Problems with 32bit/64bit exe wrapper for Java on Windows

In my ini file for winrun4j java exe wrapper I set vm.version.min=1.7 to specify Java 7 as a requirement. But when I ran it I couldn't get winrun4j to recognise that I had a java 7 jre installed even though java -version from the command line returned it.
On further investigation I realized that my Java 7 installation was 64bit whereas my Java 6 installation was 32bit. I then found that winrun4j has some 64bit version of its commands (ie rcedit64), if I built an appname64.exe rather than appname.exe it no longer complained about Java 7.
So can someone confirm this was the issue that I need a 64bit exe to run a 64bit jvm
Secondly if this is the case how do I present this to the user, I'm wrapping the installer as an exe so does that mean I need to provide the user with both an installer.exe and a installer64.exe and explain to the user to pick the right one not based on their processor but based on what version of java they have installed32bit or 64bit)
Edit:
Sounds like things are as i described, and using launch4j maybe a solution
What's the best way to start Java applications on Windows 7?
that I need a 64bit exe to run a 64bit jvm
Yes. You can not use a 32 bit exe to run the 64bit JVM
Secondly if this is the case how do I present this to the user, I'm
wrapping the installer as an exe...
Don't. Just create an installer for a 32-bit system and a 64-bit system. Depending on the target system the corresponding installer should run

What is the reason behind putting two jre, one in jdk and one outsite jdk in the java folder in Program files

I have see two jre in the java folder one in jdk and one outside jdk. Can you tell me the what is the reason behind having these two jre?
I didn't read your answer right and searched a little, here's an answer from somebody who seems to be Oracle staff:
There are some differences which may explain what you are seeing. The
JRE that is included with the JDK does not support Auto Update and it
does not contain any product offerings as the standalone JRE does. The
JRE and JDK are both built at the same time (approximately) from the
source base.
from https://forums.oracle.com/forums/thread.jspa?threadID=2277801
Old Answer 32/64 Bit Windows
If you are on Windows 7 64 Bit (or maybe other MS 64 Bit Systems) you need 2 JRE's. One for your 64 Bit Applications (Browser) and one for 32 Bit. They should have distinct Folder Names, ie:
64 Bit C:\Program Files\java\jre7
32 Bit C:\Program Files (x86)\java\jre7
If you're just running an application you only need the Java Runtime Environment (JRE), so it make sense to deliver that as a distinct entity.
If you are developing the you need the complete Java Development Kit, and it's helpful to have everything you need including the JRE.
So, two usage scenarios, two ways to get the JRE.
See the question referenced by Jaya for more information.
If you are developing a java program then compile time private jre(C:\Program Files\Java\jdk1.7.0_65\jre) will be used and running time public jre(C:\Program Files\Java\jre7) will be used.This is the default use case scenario.If compile time jvm finds that private jre is not there then it will go for public jre and run time also if jvm finds that if public jre is not there then it will go for private jre.
The JDK is required for developing Java applications, but it includes a JRE (Java Runtime Environment) which is required in order to run Java applications.
If you're an advanced user and you know what you're doing then you only need one copy of the JRE, meaning that you do not need the "Public JRE" in addition to the one that comes with the JDK.
Simply set your Environment variable JAVA_HOME to point to the JDK installation directory, and add the JRE's bin directory, i.e. %JAVA_HOME%\jre\bin, to your PATH.
If you want Java to notify/remind/annoy you about updates, and have an extra 200MB of disk space that you don't need, then install the public JRE too.

Ensure 32-bit JVM in Install4J?

I'm using Install4J mostly for it's great jar file optimization and support for pack200. The main hiccup I'm running up against is that we have several native libraries that are 32-bit only. We need to run with a 32 bit JVM for those to work, ideally dynamically downloding one and installing it when one's not there.
The case that's tricky is when there is a JVM installed above the minimum version we need, but that's 64-bit instead of 32-bit. Any way we can detect that and download and install a 32-bit JVM to run with instead?
You can bundle the 32bit JRE to installer. And instruct Install4J not to use already existing Java on user's machine but rather the one you have bundled.
I had similar problem, check Running install4j on 64bit JRE in Win.
I actually had missed the fact that Install4J already handles this. Since the launcher itself is 32 bit, Install4J requires a 32 bit JVM. So it downloads one automatically if it's not there.

Categories

Resources