Open jar file using JRE on Mac - java

I have a jar file that is meant to be ran through the command line.
I am not planning to do any java development on the machines where the application will run and my thought process is that therefore I should only need the JRE and not the JDK. In addition, the JDK is like 4x as big as the JRE and I would like to not have to download it.
When installing the JRE on a Mac, it does not set the path for the java command and if I try to run it, osx prompts me to install the JDK.
I wonder if anyone could provide some insight as to how to use the java command in a mac without having the download the bigger sized JDK?
Thanks a lot.

Have you tried running this in terminal?
java -jar MyJarName.jar
However, you can also try and make a runnable application of the jar file. Take a look at Packaging a Java App for Distribution on a Mac
EDIT:
You can also try running your starter class from the terminal. cd to the bin folder of your project, then java packageName.className. For example, java my.package.Starter.

Related

Create standalone executable from Java code for Windows, OSX and Linux all at once

i'm coding a project in Java and building it with gradle.
I need to keep it simple and compile it into standalone binaries for Windows, Mac and Linux.
Is there anything which can build all of this binaries or must i use a separate lib (like Launch4j for Windows executables) for every single binary?
I'd like to call a single "build-all-binarys"-like task in gradle and get a .exe, .app and .bin file out of it.
It would be nice to have the possibility to bundle a JRE into the binary as well.
Use the javapackager, added since Java 8 in the JDK.
It nicely creates a self contained executable - that's it bundles the JVM with every copy - of all standard operating systems with one call.
The javapackager is located in JAVA_HOME/bin/ directory.

Can't run JAR file

I have a finished program that I created a JAR executable from (I created this in eclipse), and I need to download this executable onto computers different from the one that I wrote the program on.
However, I am getting the problem that when I try and download the executable onto the computers, I get the window that pops up that says that "Windows can't open this file" and it then gives me a list of programs that I can open the file with, none of which I can use. I do not need to do this on the computer on which I wrote the program. When I double-click the executable on that computer, the program starts without any trouble.
In order to run Java programs, you have to install the Java Runtime Environment (JRE). The Java Development Kit (JDK) is not needed. You can download the latest version (JRE) here.
If you want to learn more about JVM, JRE and JDK, you can read the answer to this question.
This is cause you need install Java in the remote machines including the JDK, then also you need to make java available through console installing Ant wherever it applies.

Creating a windows .exe from a runnable jar (preferably on linux)

I have an application packaged up as a xyz.jar, which can be run as java -Xmx2g -jar xyz.jar
How can I convert this to a self-contained exe that can be downloaded by Windows users and launched with a single click? Preferably, I'd like the jre also bundled inside the exe, much like can be done from the mac: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
Oh, and also I'd prefer if I can do this from an ant build file (or eclipse plugin) on a mac or linux platform, since I don't have easy access to Windows (though my users do). Is this possible?
Thanks.
Take a look at Launch4J, it's cross platform so you should be able to generate the executable from any platform your build is running on. IIRC it also have an ANT task ready to be used.
http://launch4j.sourceforge.net/

Java Browser Plugin Or Manually installing Java

Here is my question i installed Java Plugin for Chrome it does mean i have installed java in my machine...And after installing this plugin can i run below command
java -jar myfile.jar
through a batch file or i have to install java in my machine and setup class-path then it should work?
If i will install Java browser plugin it automatically installed java in my machine and setup path as well.
Its hard for me t understand the situation how it works. Can anyone help me on this?
The JRE is the Java Runtime Environment, i.e. the software you need to interpret and execute Java class files. The Java browser plugin is the bridge between the JRE and the browser, used to run Java classes of applets embedded in HTML.
You can check the Java plugin of Chrome browser in this link.
The plugin is bundled with the JRE, and runs inside a browser, allowing Java code to run inside the browser process on the client. The main entry point class must be written as an Applet when the plugin is used, but all the Java code it calls can be just regular Java.
There are limitations when running Java code with the Java plugin for security reasons. All code shall run within sandbox with limited access to the file system and such.
Also as the plugin check for installed JRE version at your machine, that means you do have JRE.
You can install as many JDKs as you like. Just put them in different folders.
The one you refer to on the path is your choice - but presumably you'd choose the one that you want to use whenever you type "java ...." commands at the command line. In the absence of any other factors you should probably set this to be your most recent JDK version.
Note that your IDE may support multiple JDKs, for example Eclipse has "Preferences / Java / Installed JREs" where you can set up multiple JDKs/JREs for use with Eclipse
Please first check your machine contains java (jdk or jre)
java -version -- if you get a valid output then you have java in your machine.
in order to run java -jar myfile.jar , you should install java (jre or jdk) in your machine and class path set to the relevant location. To run this you should install jdk or jre in your machine. Most program only need the JRE (Java Runtime Environment) but some programs need the Compiler at runtime in which case you need the JDK.
Please refer this link to find out How to set class path .
Then you will be able to run your command.

JAR file does not load class files from ext

I installed JDK 1.6 on my Linux system, the $JAVA _HOME directory is /usr/java/jdk1.6.0_07.
I built the path on Eclipse to $JAVA_HOME. It runs smoothly through Eclipse and loads all third party JAR files from /usr/java/jdk1.6.0_07/jre/lib/ext/, but when I export the JAR file and run it, it throws ClassNotFoundExecption.
Why?
Did you install Java properly? Here are some instruction for installing Java 7 or Java 6
Are you sure that the version of Java you are using is correct one since there can be several versions of java on linux? Try java -version on terminal where you run it to check.
Do you use any third party library? If so, did you specify the class path when you run the jar file or bundle them inside your jar file?
What does java -version return? Are you using the same JRE for execution?

Categories