How to run Java file on Google Cloud VM? - java

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.

Related

Downgrade from Java OpenJDK 64-Bit Server VM 1.8.0_292

Good morning, I have an application that works only with Java OpenJDK 64-Bit Server VM 1.8.0_292, however we are in the Java OpenJDK 64-Bit Server VM 1.8.0_312 version. How can I install it?
Go here: https://adoptium.net/releases.html?variant=openjdk8
download package
extract package
try calling it direclty (/new/path/jdk8/bin/java -version). This should now differ from calling the default java (java -version)
instead of calling the first java the systems finds (like java -Xmx500G -jar yourApp.jar), run your app via direct java path call: /new/path/jdk8/bin/java -Xmx500G -jar yourApp.jar
For Windows you can create .bat files, for linux you can create runnable bash scripts etc.
Oh, and a little side note: if that app is really only running under a certain revision version of java, it's probably really bad software...

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.

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

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.

How to prevent TextPad from creating temporary batch files when running Java?

This is my first post here, so, please let me know if I posted this question in the wrong place or something. Thanks.
So, I recently reinstalled the Java SDK and TextPad after deciding that I wanted to get back into Java programming.
I compiled and ran a test Java code to see if everything got installed correctly. All seemed well until I happened to take a look at the folder containing my .java and .class files. I noticed that a bunch of batch files had populated that folder while I was messing around with my test code. I don't recall these appearing back when I was learning Java and using an older version of TextPad.
Is this something that TextPad does now? Is there a way to prevent this from happening? Or, I suppose a better question would be, does this happen to anyone else or is this only happening to me? If it's only happening to me, then what did I do wrong during my installation of the Java SDK and TextPad to cause this to happen?
I mean, once I exit out of TextPad, the batch files get deleted, so, it seems that they're temporary files. However, like I previously mentioned, I don't recall this happening back when I was learning Java and using an older version of TextPad, so, I would like some insight into preventing these batch files from being created every time I run a compiled Java code through TextPad, if possible. They're kind of annoying, in my opinion.
TextPad Info:
Version 6.1.3 (32-bit)
Java Info:
Version 1.7.0_09 (64-bit), Java(TM) SE Runtime Environment (build 1.7.0_09-b05), Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
OS:
Windows 7 (64-bit)
Content of one of those batch files:
#ECHO OFF
C:
CD "\Users\<PATH of class file>"
"C:\Program Files\Java\jdk1.7.0_09\bin\java.exe" -classpath . test
PAUSE
Thanks in advance. :)
You could create a local user that only has read permissions to the TextPad installation folder (or wherever the temp files are being created) and then run TextPad as that user.
Once you create your user, modify your TextPad shortcut target to the following:
runas /user:TextPadReadOnly "C:\path\to\TextPad.exe"
It's very possible that TextPad won't even run afterwards, but if it does it should do what you want... Short of reprogramming TextPad, I doubt there's any other way to fix it (if there's no setting to disable this behavior, which I'm assuming you've looked for).

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