Can I copy the Java Runtime Environment to other Computers? - java

I have the following problem:
I wrote an application in java for my company. Now i have the problem that not every user has the jre installed on his pc. And due to company guidelines its not that easy to install it on every computer.
My question is: Can I write a batchfile which checks if the jre is already installed and if not copies the jre onto the computer? Would the jre work if I just copy it?
If you have another solution for my problem feel free to tell me.
Thank you for your answers

Bundling a Java desktop application with a JRE is in fact nowadays considered good practice. How exactly to do that depends on the target operating system. But there's usually no need to come up with an individual solution as Oracle provides instructions on how to achieve this in a standardized way.
This is what Oracle says about the basics of "Self-Contained Application Packaging":
Each self-contained application package includes the following items:
Application code, packaged into a set of JAR files, plus any other
application resources (data files, native libraries)
Copy of the JRE, to be used by this application only
Native launcher for the application, multiple launchers for a single
package are supported
Metadata, such as icons
They provide detailed instructions for Java 8 and Java 9 on how exactly to create the package for different operating systems.

Related

Embedding OpenJDK in Application

I know it's possible to bundle the regular Oracle JRE in a Java application if you want to distribute it as a stand-alone application without requiring users to have the JRE already installed, but is it possible to do the same thing with OpenJDK?
This question is old, but an answer seems appropriate today (since this is new-ish)
The Java Platform Module System (Java 9+) supports this idea directly with the jlink tool. It's actually one of the specific, stated, goals of the system. And, to make it even better, a properly modularized software product will include only the necessary parts of the JRE and libraries, thereby remaining relatively small.

What is the preferred way to deploy a jar to people who don't have java?

I have a program which is being distributed to companies where java is either not allowed on their computers or not allowed to be updated for various security reasons. It is a java jar as it stands, a simple survey-type desktop program using swing.
My question is, how can I distribute this program to the various end users when they aren't allowed to install anything on their systems, including java? They will be running the program from a flash drive, so it has to just run from there with no installation or copying to the disk or anything like that, and no guarantee that java will be installed.
All of the target users are on windows, at least, so an exe is an option.
EDIT: Based on what Rob has said, does anyone know if distributing a private JRE is possible? Bundling a JRE which is preinstalled on the flash drive, and then pointing the jar to that?
I don't believe that there is anyway to do this using Java. The role of the JVM is to interpret the java byte code into instructions which will function on the device which the JVM is installed on. If no JVM is installed, your intermediate code (JAR file) can't be run.
You may look into distributing your app via ClickOnce if .Net development is an option. It will allow Windows users to install and run applications with limited permissions even without administrative access on their computers.

Installer for Java Desktop Application

I am developing an inventory system i-e a java desktop application. I am using Ms Access as database engine and there are certain modules e.g one makes reports using ireport and other such dependencies. I need to ask how can I make installer for my application which will install few fonts, copy database files, install jre to make it run etc. Please guide me in it.
Thanks in anticipation.
This is something I've briefly used in the past, and it may serve your needs. It's an open source installer builder system, tailored towards Java apps.
http://izpack.org/
I've used jsmooth which creates a single EXE-file that unpacks and run transparently. Not a full installer but worked well for us.
Note: I have not seen any Java installers which asks the "There is an update available. Update now?" question.
If this is important to you, then consider Java WebStart which checks for updates at each launch (but do not ask).

Is Java cross platform?

I want to develop a cross platform application.
Is Java cross platform? I mean, can I develop a Java application in Windows and use it in Mac OS X and Linux?
If yes, how?
I find application written in Java, has two setup file one for Windows and other for Mac. This confuses me.
Any illustration or suggestion will be highly appreciated.
Is Java a cross platform?
Java is cross platform in the sense that a compiled Java program runs on all platforms for which there exists a JVM. (This holds for all major operating systems, including Windows, Mac OS and Linux.)
I mean I can develop Java application in windows and use it in mac and Linux?
Yes, this is possible.
This (and the security aspect) is one of the main advantages of running the programs in a virtual machine.
If yes how?
Write your application in Java (In .java files)
Compile your application using Eclipse or javac (into .class files)
(Optionally) Bundle your .class files in an executable (.jar file)
The very same .jar file can be distributed and executed on Windows systems, Mac systems, etc.
I find application written in Java, has two setup file one for windows and other for mac. This confuses me.
This is because some applications rely on platform-specific features. They are then bundled with different platform-specific libraries.
Unless you're developing an application that itself relies on platform-specific features, (such as for instance low-level system calls), you should be able to do just fine with ordinary Java.
Important comment by #Peter Lawrey:
It can be while the application is platform independent, the setup program is not. e.g. IntelliJ has three platform specific installers which are not written in Java, but have a zip which you can just unzip on any platform and it will work.
You can run Java applications on every device that has a JVM. If it does not, you're out of luck.
The comment from Oded is important. C and C++ have compilers on lots of devices.
Java byte code won't need to be recompiled when you switch platforms.
C and C++ will require that the developer recompile the application before distributing it to the target system, but once that's done clients will be able to run without an issue.
The problem of platform-specific customizations and settings has to be dealt with no matter which language you choose. The more your application depends on platform-specific features, the less portable it will be.
UPDATE:
Let's revisit the original words in the question:
I want to develop a cross platform application.
Here's the objective - a direct quote. No details about web, mobile, or desktop app.
Is Java cross platform? I mean, can I
develop a Java application in Windows
and use it in Mac OS X and Linux?
Define "cross platform". Sounds like the bias here is "byte code portability". C/C++ can't do that, but "source code portability" is certainly possible as long as you stick to ANSI C/C++ and refrain from using vendor extensions.
Java's claim to fame from the beginning has always been byte code portability. That's what the JVM gets you. That does not mean your whole application will be portable, because you might not have managed other dependencies well.
If I substitute "C/C++" for "Java in that bloc, then cross platform means something different. I cannot pick up a .exe or .so compiled for one platform and expect to run it on another, but if I create an .exe or .so for each platform and make them available it's certainly possible to make the same source code runnable on multiple platforms.
If yes, how?
If you have packaged your Java app as a JAR, you can put that on any platform you like.
If you have multiple C/C++ .exes for the platforms you're interested in, you can certainly run it when you need to.
There is an important caveat with regard to Java portability. "Business logic" (non-UI stuff) is quite portable, but there are at least a half-dozen different (and incompatible) user interface paradigms for Java, so, eg, Java code written to run on an Android (even ignoring Android's incompatible JVM) won't run on a Nokia phone, and code for either one will not run on a desktop PC.
But there's no other language that does better, to my knowledge.
Yes, Java written and compiled on one OS can run on another OS. There are JVMs available for many modern operating systems.
Java apps are packaged as .jar files. These can run on any operating system that implements the correct Java Runtime Environment for the application, provided the user has installed that JRE (JREs are provided to users for free).
The precise procedure for running the app is different for each operating system.
The Java Development Kit provides libraries that allow system functions (e.g. file operations, user interfaces) to be invoked that ought to work on any OS. However the precise behavior may vary (in a similar way to how a website can look different in different browsers). Also, Java apps may have a 'look and feel' that does not precisely match the look and feel of applications designed specifically for that OS.
It depends what you mean by "cross-platform". Java code can be compiled to byte-code binary class or jar files on any OS supporting the JDK and run on any platform supported the JRE. However, most compiled languages can be compiled on any platform provided the designers has catered for it. Java is more easily portable than, say, C++, but that doesn't mean C++ code won't be able to compile on any platform.
In other words - don't choose your language on this single feature alone. Choosing the best language for your application would be a better way of going about it. Perhaps a scripting language would be best for you. Maybe post another question asking what language to use to solve your specific problem.
I wrote a little game in Java with sound.
I've used standard library (AudioInputStream and Clip classes).
The program works very good with Windows XP, BUT I haven't got the sounds with Windows Seven or Linux Ubuntu.
Java 6 was installed for all those OS, and I've compiled the program with the standard compiler JAVAC.
So Java is not so "cross platform".
JAVA is not really cross-platform because is just a design, some JAVA implementations can be cross-platform but it really depends on the JAVA implementer.
SUN/Oracle makes the JAVA standard implementation for Windows, MAC and Linux and if you build programs with their JDK you should run the programs with their JRE, if you try to run it with other JRE there might be compatibility issues.
This can be seen more in the mobile, some phone makers won't make a full implementation of JAVA because hardware limitations or because they want to control the device's software, they carry the JAVA logo but you must use their own JDK and those programs could not run outside of their JVM implementation.
Another issue with JAVA is that some functionality could be deprecated and what ran in some specific version of the JRE could not run in newer versions or run in a different way.
The big problem is when we are talking about mobile apps. For desktops OS, java can run perfectly, but for mobile devices, developers can, practically, only create for Android. There are tools like Totalcross that helps java developers to create apps to iOS and Android. The focus is maintain the WORA assumption to every platform, even mobile.

Java Deployment

When deploying a Java application, can I assume that every computer has java, and so is able to run my application? I've just created a java app, which works on my computer, but my boss (who generally uses .NET) claims it doesn't work at all. Should I assume that this will happen often, or will most consumers have java?
I think it is better to NOT assume that all computers have JRE installed. Just like development practice you need to have a deployment strategy for your application.
Here are some of the questions you need to find answers to arrive at a better deployment strategy:
Which version of JRE is needed, what if the computers on which the application is run has an older version of JRE ?
What all platforms (windows, linux or both ) your application is going to be run ?
Is there a IT policy that ensures that a standard version of JRE is available on all the hosts ? In this case
you can make a valid assumption that all computers on which application is run has the JRE installed?
If you need a specific version of JRE which is not available on all the computers may be you have to bundle the
JRE along with your application.
I think that you should provide to your users a way to download/install the jre (probably a link) with a friendly message explaining the need to install it.
Java is widely use.
NOTE In example, following is an example of the applet tag:
<applet code=Applet1.class width="200" height="200">
Your browser does not support the <code>applet</code> tag.
</applet>
If you are deploying your application in a traditional way, there are some java application installers that handle it for you.
I hope it helps you.
You can also deploy a jre along with your application. Many 3rd party applications do this to ensure that the proper version of Java is available on the system. There are pros and cons with each approach.
You will want to refer to the license information about redistributing the jre contained in the jre folder ( e.g C:\Program Files (x86)\Java\jre6\README.txt - or wherever your install is ) to ensure you follow the proper procedures.
There are a number of solutions. You should not assume that everyone has Java installed. You can use web start for instance which will help with the setup. You can find some advice here.
More info about web start here.

Categories

Resources