Get a Java program to run on a computer without modern JRE - java

I made a simple text based game that runs on my computer, but my schools computers have an older version of java and can't run it. I tried compiling the .java file in from the computers command prompt but I can't access where the javac folder is to compile because the school computer blocks everything. The command prompt is even disabled by the administrator unless I open it with a batch file. I tried wrapping the jar with the JRE in Launch4j but the exe does nothing, it loads and that's it, nothing comes up (I think it's because the text game is supposed to run in the command prompt so there is no GUI to print any of the text)
How to get a Java program to run on a computer without modern JRE?

my schools computers have an older version of java and can't run it
Use the cross-compilation options of javac when compiling it at home.

You are running into a bit of a contradiction here; Please take notice on what exactly you are asking:
"How can I run a Java Program without Java?"
Do you get it? You are basically asking "How can I drive a car without the car?"
As for the actual problem, all hope is not lost. Here are some options:
If possible by any means, simply install the latest stable version of Java on the machine.
From a computer that has JRE/JDK installed (or through another form of access to the JavaCompiler, AKA JavaC), recompile the code to the older version of Java using the command-line parameters for source and target java versions (Note: I am unsure if the JRE/JDK for the older version must be installed in the machine or not).
For this case, you might want to take a look at this and/or this.
Choose another language to work with, and re-do your code into that language; You can't run Java code without Java, the same way you can't travel by train without the train to travel with.

Related

Java application not working on other systems

I've made a word-processor named StoryTeller in Java (a first - beta version, which I'm still working on improving) and put it online for others to test out and use.
I've gotten a response saying they were unable to open it. I've built and run StoryTeller on Windows 10 OS and it works fine. After generating the jar file, I used Inno setup to generate an installer for the program. You can find the file I've uploaded here. Here's the message I got about it:
Hello! I was going to try out StoryTeller on my Macbook today, but unfortunately it didn't work. The file automatically gets opened in
"Text Editor" where encrypted text shows up along with the error
message "this program must be run under Win32".
I downloaded it on my old computer earlier this week (it has windows
7) and the download process and installation worked perfectly fine,
but I was unable to open the program when the installation was done.
It appeared on my desk as a Java-symbol (the icon) and nothing
happened when I clicked on it. Both my OS are quite old (Macbook from
2010 and the other computer from 2012), but I've still updated them as
much as possible and installed all the latest versions available of
necessary programs, so I'm not sure whether the problem lies within my
computers or StoryTeller itself.
Do you have any ideas how I can fix this? I would really like to try
StoryTeller since it seems to be a great concept that could really
come in handy when I work on my novel.
Could anyone help, please, understand what may be the issue here? Thanks.
First, check if your JDK is 32-bits and make sure to advice your future users have a 32-bit JRE installed. This way, it may work properly. I think 64-bit Java apps can't run atop a 32-bit JRE;
You can bundle a proper JRE/JVM with your software;
Make sure you are referencing ANYTHING with absolute paths inside your code. This could make your software throw several exceptions when running somewhere else;
For instance, Inno-setup commonly generates Windows-only .exe setups. Installing your software in a Mac would require you to generate a .dmg or .pkg (this one you could create through PackageMaker extension from XCode here (require registration, more info here
Kappy on Jul 5, 2012 6:28 PM says: Go to connect.apple.com and search for "packagemaker." Of course you must first be logged into your developer account.
))
For Linux, you can provide a simple shellscript bundled with your .jar (even with a discrete JVM) in a .zip or .tar.gz file, and ask your future users to run the provided shellscript.
Good luck!

How can I tell a Linux Distro to apt-get install LibVLC if it doesn't have it from a running Java Program?

I'm working on a program that utilizes Caprica's VLCJ Bindings.
This is fine and good for Windows and Mac, as I can just package the VLC Libraries for them in a zip file and output them to the user machine where appropriate.
The problem comes when I need to do this for Linux, because, dear god,
there are ELEVEN. SEPARATELY COMPILED. APPLICATIONS/LIBRARIES.
And some of them even have their own flavors. It's like the Baskin Robins of OS's (I knew there were a few but I've only really ever run Ubuntu so I was not prepared for this).
If I was a masochist I could totally make this work and end up with a gigantic jar with an absurdly huge number of zipped Linux libraries within it, but I really, reHEHEHEALLY do not want to do that.
So I figured that the best course of action to take would be to check if LibVLC is installed, and if it is, reference it directly, and if it isn't, install it at run time (before the library tries to load itself), or, heck, even at launch/install time for the Java program.
Is this possible? I know that on Ubuntu using the terminal it would be something similar to
sudo apt-get install vlc
and there's probably 15 different flavors of that, which is fine, I can deal with that, but is it possible to do that from within a running Java application (and wait until it's finished before moving on), and if so, how can I go about doing that, and if not, how hosed am I?
To detect if LibVLC is already installed it's possible to do that in pure Java simply by searching the file-system using Java File IO. The idea is you'd look for "libvlc.so.*" in "/usr/lib" and/or other "well-known" locations.
vlcj provides a NativeDiscovery class that will do this for you:
boolean foundLibVLC = new NativeDiscovery().discover();
You can find Javadoc here.
You could then throw up a dialog box to prompt the user to install vlc using their package manager.
Or you could detect the OS by using Java File IO to read "/etc/issue" and if it were Ubuntu you could launch a process to run "apt-get install", or a different package manager for a different distro. I've used Apache Commons-Exec to do this sort of thing before.
There's simply no universal package manager you can assume across the different distros.
I know it's not ideal, but this is what I do for my projects.
To be fair, if you're targetting users on Linux you're likely to be targetting more technically savvy users than most and they would likely have no problems installing other software.
A further option I suppose is to ship the VLC source code with your project and have your installer build VLC. It takes a while to build VLC from scratch though, and there are lot of third party library dependencies that must be installed first.
I suppose on Linux, the 'correct' thing to do is to create a distro package (like a .deb or .rpm or something), declare a dependency on VLC, Java and JNA and do it that way.

Running Multiple Java Versions

Hopefully someone can help me because I am apparently brain dead. I have searched and read through a lot of this forum as well as others for help in resolving my problem and I am just not getting it.
I have 2 Java WebApps that I need to run for Johnson Control HVAC units. The one unit is old and strictly requires Java 1.6.0_21. There are no upgrade options available for this unit. Just hundreds of thousands of dollars to replace the whole system. But the system works just fine so I am not interested in replacing it.
Now I have another unit which my company just took over at another location that uses a similar control unit but runs on Java 1.7.0_49 or 69 I can't remember. I have both versions installed on my computer but only the newer unit with Java 1.7 works. My older one now comes up with Unable to Launch Application Error. I have tried all these things and either I am just plain doing it wrong or something else that I am not catching is up.
I tried going into the Java Control Panel and unchecking Enable 1.7. That had no affect, even after rebooting.
I went into the Environmental Variables and under Path I have no Path to Java. So I added the path to the Java 1.6 version which also had no affect.
I have a batch file on my desktop to run the older app because it's web URL is a mile long. In this batch file I tried to add set JAVA_HOME variable and a set PATH variable for Java 1.6 which also had no affect.
I tried just doing java -version:1.6 from the cmd prompt which also did not allow the program to start.
I got it so when I did java -version from the cmd prompt it would tell me 1.6.0_21 for the version but I still can't get the program to load.
So I uninstalled 1.7 from the computer and tried it again. Still would not load the program. I had to reinstall the 1.6 before the older program worked. But once I reinstalled 1.7 I was back in the same boat.
I tried re-installing both programs using the STATIC=1 command through cmd prompt and still only version 1.7 runs and the older 1.6 does not.
I do get a message when I try to load the 1.6 that says, the program has requested an older outdated version of the program. Open with new version recommended or open in the older requested version 1.6.0_21. I select open in the older version but still get the Can Not Launch Application Error.
I have also tried going into the advanced settings and unchecking Internet Explorer for the Browser in the 1.7 control panel and going into the 1.6 control panel and checking Internet Explorer.
What am I doing wrong here or what am I missing? Any help would be appreciated.
This is a Windows XP 32 bit computer. Nothing special, just a word processor mostly.
You are swimming upstream, but it isn't a very large or strong stream, and this can be done.
The upstream part is that most instructions for doing this assume you are going to run only one version of the JVM on a given machine.
The good news is that Java doesn't require this, and is not set up so that it is difficult to run two at the same time. You just have to be rigorous about where each of them get their information.
I would recommend not "installing" EITHER of them. Do not put the executables' or the libraries' directories on your path variable, and do not define a CLASSPATH variable on the machine globally. You will need to unpack a runtime environment for each JVM, each in their own directory tree.
Make one batch file to run each version. It will define its own path variable, and its own classpath (either with SET CLASSPATH= or using the classpath JVM argument).
Good luck.

Stand alone java program

New to java programs so apologies for the noob question. I have written a java program that I run using "java myprog" command in a terminal window. I want to give this program to friend but not sure what that person needs as a minimum to run the program. Can the code be compiled to run completely independently of any java installation my friend may or may not have? Will the other person need to recompile the code?
Option 1
You can give them the compiled output (the .class) file.
They need a version of the JRE (but not the JDK that developers need to compile) that is compatible with the version you used to compile your code. The simplest way is just to match versions. For example, if you're using J2SE 7, then get JRE 7 for your friend.
With this your friend should be able to type java myprog and get the same results as you. If you want your friend to run the program from the command line the same way you do, then this is probably the simplest approach.
So, if on both your machine and your friend's machine you type:
java -version
...and you get the same major version, then you're probably in the right ballpark.
Option 2
You can also create an executable .jar file if you want something your friend can just double-click, but they'll still need a version of the JRE installed, and creating executable JARs can be a bit difficult if you're new to the language. They take some learning and trial-and-error time. This is definitely a more complex approach than option #1.
Option 3
There are compilers that will convert your java program into native code (an .exe file in Windows), but you'll need to know what OS your friend is running, and make sure you're compiling for your friend's OS.
One example of these tools that I heard about years ago is Excelsior JET (though I'm not endorsing it as a tool - just saying that they exist).
This is definitely the most advanced/most difficult of options, and includes even more trial-and-error than option #2, but if you're talking about a really simple program with a single file, then it might be very straightforward.
Of course, Excelsior JET wasn't free last time I checked.
I've written an entire article on this very subject:
Convert Java to EXE - Why, When, When Not, and How
You want to create an executable .jar file. Provided that your friend has Java installed, he can run the program by simply double clicking on the file.
Java programs are usually compiled into Java bytecode - not to a native executable. Once compiled, the resulting class files will be executable on any JVM that is recent enough, regardless of the underlying hardware platform or operating system. In order to have a JVM, however, your friend would typically need to have an appropriate Java Runtime Environment (JRE) installed.
Alternatively, there are ways to distribute a program along with a JRE, but I believe that this approach is not trivial. There are programs, such as launch4j, that can automate the process somewhat, if you want to go that way.
The options given above suggesting giving the .class file and using java myprog may not work if the friend is not located in the directory where myprog.class has been placed, as the class path may need to be specified. So the friend may have to use java -cp path_to_myprog myprog

My program requires java JDK to run?

this is a kind of weird non programming (but java related) question.
I created a java program (game) using just normal java, and no libraries.
In ordor to double click/open it, you need to have java SDK/JDK (I don't know which) installed.
I tested this multiple times, and in order for my PC and Mac to launch it, you need to install it.
is there anyway to get around this? I know Minecraft doesn't force you to download the JDK.
Here's the link to source code of my game if your interested (no, it is not a virus): http://www.filedropper.com/daplatform
Thanks, Jake
Here's the link to the download of the JDK (Its next to the giant Netbeans download): http://www.oracle.com/technetwork/java/javase/downloads/index.html
What you can do is you can wrap both your program and the JRE required to run it into a single executable for the target platform.
For example your windows installer would include both a windows JRE and your program itself.
Launch4j http://launch4j.sourceforge.net/ lets you wrap a Java program into a windows executable and gives you options about how to handle the JRE, including bundling it.

Categories

Resources