Running Windows-compiled C++ program on Linux machine using Runtime - java

I need to run an executable on the command line through Java. I have seen a lot of information about this and using the Runtime object to execute the file. However I have a problem: the executable is written in C++ and compiled for Windows, but I'm using Linux. I have no access to the source code.
I read in the documentation of the Runtime environment that
Runtime that allows the application to interface with the environment in which the application is running
The environment I am running it on is Linux, so the application would not work if the application is interfacing with my Linux environment.
I am curious if there are any other objects other than Runtime that could do this, but mimic the runtime of a different OS. For example maybe a WindowsRuntime object or something that you could call and have the application run without having to recompile it for Linux. It seems like this could be pretty complicated (perhaps like a virtual machine) but thought it was worth a try.

Related

cross compiler for java for ubuntu on windows

I am deploying a java application in windows IDE but this application will be run in Ubuntu. What cross compiler do I need to compile in windows and then deploy it in Ubuntu?
Thank you,
All Java compilers are cross-platform. That's one of the most important characteristics of Java.
Java compiles to byte-code, which is the interpreted by a virtual machine. If a computer has a virtual machine it can run byte code generated in any operating system.

How to run Java file on Google Cloud VM?

I want to run a java file on a VM instance I've created in Google Cloud under Compute Engine. However, it's not clear how to do this. I pressed SSH and uploaded the java file but I dont know what to do after that. It doesn't allow me to start the VM. Please, does anyone know how to do this? Run a simple java file on Google Cloud's VM?
You can't SSH into a VM that hasn't been started so the fact that you can SSH into the VM implicitly means it has been started.
If the .java file is accessible to the VM and the relevant JDK has been installed on your VM, you can compile and then it run like you'd run any other Java program. You can use javac for the compilation and java to run the compiled .class file. You can take a look at this article for more info on how to do that.

What is the difference between Java components (JRE, JDK, JVM, JIT, and javac)?

I've had a hard time while understanding the difference between JVM(Java virtual machine), JRE (Java Runtime Environment), JDK (Java Development Kit), JIT (Just In Time Compiler), and javac (Java compiler).
What is a good comparison and contrast between all of these?
You might have done so much of google to find the answer of this question and came across a very boring diagram showing the architecture and interrelation between JVM, JRE and JVM. It took me almost a year to understand it practically (not theoretically).
Let’s find out the answer of this simple (but yet very important) question:
What is JDK, JRE and JVM?
JDK:- Java Development Kit (in short JDK) is Kit which provides the environment to Develop and execute(run ) the Java program. For eg. You(as Java Developer) are developing an accounting application on your machine, so what do you going to need into your machine to develop and run this desktop app? You are going to need J-D-K for that purpose for this you just need to go to official website of sun or oracle to download the latest version of JDK into your machine.
Hence, JDK is a kit(or package) which includes two things i) Development Tools(to provide an environment to develop your java programs) and ii) JRE (to execute your java program). JDK is only used by Java Developers.
JRE :- Java Runtime Environment (to say JRE) is an installation package which provides environment to only run(not develop) the java program(or application)onto your machine. For eg(continuing with the same example) after developing your accounting application , you want to run this application into your client’s machine . Now in this case your client only need to run your application into his/her machine so your client should install JRE in-order to run your application into his machine.
Hence, JRE is only used by them who only wants to run the Java Programs i.e. end users of your system.
JVM :- Java Virtual machine(JVM) is a very important part of both JDK and JRE because it is contained or inbuilt in both. Whatever java program you run using JRE or JDK goes into JVM and JVM is responsible to execute the java program line by line hence it is also known as interpreter(we will discuss about interpreter later) . Hence you don’t need to install JVM separately into your machine because it is inbuilt into your JDK or JRE installation package. We’ll explore more about JVM soon.
Finally after learning about all the three main parts of java you can have a look at the above figure to have clear understanding of the architecture and interrelationship between all the main components of java.
Well, I want to tell you my understanding about it.
JDK (Java Developer's Kit) is a complete Java development platform. We can compile, debug and run the code. The JDK depends on the operating system, so there are a little version classify by Windows, Linux and Mac.
JRE(Java Runtime Environment) is the runtime environment of Java. If you had ever played any game which written in Java, you can find that you must have JRE when you is going to play the game. This is the Java Runtime Environment.
JVM (Java Virtual Machine) is a part of JRE. It is the most important part of the JRE.
JIT is the tool which can transform bytecode to the binary code.
javac is the tool which can transform code to the Java bytecode.
We can conclude the relationship:
JDK = JRE + javac + jconsole +jvisualvm + demo + document + other
JRE = JVM + JAVA binary code + other library + other
JVM = JIT + Other

GCJ: Java native code, won't run on other machines

I tried GCJ and it compiled fine. I tried both for Ubuntu and windows. The compiled file is running on my Ubuntu machine as well the .exe with wine. But if I tried to run in on my Ubuntu server I got this error:
error while loading shared libraries: libgcj.so.14: cannot open shared object file: No such file or directory
But I thought I would not need to install anything to run "native" code. I also could not run the .exe on a windows machine.
Could you please tell me why this is happening? Maybe I'm compiling wrong. I use this: gcj --main=Hello -o hello.exe Hello.jar for windows.
When you run an executable it is very common to need a shared library, whether you use Visual Studio .NET or Java or C++.
When you compile a program for a specific platform, it usually only works on that platform or similar. If you want to run this program on Windows, you need to compile it for windows.
BTW GCJ is pretty old and out of date. I suggest you use Java 7 or 8. This will avoid the need to install additional libraries and will run on Windows or Linux without re-compiling.

Java server jvm installation on windows 32 bit systems

I am trying to bundle java as a part of a java product that should be installed silently with a single click and are having some issues:
My installation has the following requirements:
Has no be silent and require no user input or action excpect a doubleclick on the installation file (no configuration and post install steps)
Has to setup java so that JAVA_HOME points to a Java SE installation with a server jvm
Is this at all possible to do this on a win32 system with sun java installers? I know that by default the jre does not contian a server jvm. But even when installing the jdk the public jre which is installed (and mapped to JAVA_HOME) does not contain a server jvm. In sun own README file (Sun README) they suggest copying the files:
jre\bin\server\
On Microsoft Windows platforms, the JDK includes both
the Java HotSpot(TM) Server VM and Java HotSpot Client VM.
However, the Java SE Runtime Environment for Microsoft Windows
platforms includes only the Java HotSpot Client VM. Those wishing
to use the Java HotSpot Server VM with the Java SE Runtime
Environment may copy the JDK's jre\bin\server folder to a
bin\server directory in the Java SE Runtime Environment.
But this solution is difficult to automate gracefully in a silent install. There has to be a better way to do this without repackaging the entire java distrubution. Has anyone encountered the same problem and come up with a more elegant solution?
For the past years, I manage Java like this: I download the installer, install it somewhere, package all files into a ZIP and then use that ZIP file to deploy Java anywhere. The installer will leave a lot of stuff in the registry and %WinDir%, etc. which you don't really need. This also allows me to move some files around (like the bin\server\jvm.dll or security related settings).
That way, I can even embed Java inside the application directory, independent of any already installed version of Java.
Just set JAVA_HOME in a small batch script before starting your application and you're good. You can use %~dp0 to make it completely position independent (%~dp0 expands to the path leading to the batch file).
Make your own installer.
I use inno setup compiler, works well for my purpose.
If you need the registry entries, you can export them, include them in the installer, include the files, and a little change here and there and you're done. Silent installer that configures things to the exact specifications you need.
It comes with an easy to use script wizard.
I mention a specific one because it's free. Ultimately, making your own installer is the solutions.

Categories