How can I execute a .jar file from the terminal

1

by

jaorizabal

Last Updated November 28, 2015 13:01 PM

I know that to execute a file, I use the . command, then the file name with a space between them. But I'm trying to execute a .jar file using the . and it does not work. I went into the properties and marked it as executable and made it run with Java.

Is there a way to execute a file with Java in the Bash Terminal?

I am trying to execute the Minecraft.jar file.

Answers 6

If it is an executable jar, then

java -jar Minecraft.jar

Not all jar-Archives contain an executable class, declared to be started in the Manifest file, but if there is, this will work.

Btw.: You don't start most programs from the shell with the dot. The dot is a shortcut for source, and it only works in the bash and some other shells, to include a script in the scope of the current session.

A compiled binary xybin is simply started with its name if it is in the path:

xybin

or, with its...

0 0
2

Home » Newcomers » Newcomers » How do I run a .JAR file from the terminal?(Ubuntu 12.10 32 bit .JAR file wont execute from command line) On 3/7/2013 3:27 PM, Hugh Foster wrote:
> I got a error when I tried to run a java file from the terminal sayiing,
> "unrecognised option"
> Error: Could not create the Java Virtual Machine.
> Error: A fatal exception has occurred. Program will exit

Need a bit more information.

(Don't count on previous threads with different names or a running
conversation with anyone to supply it--I do know you were wanting to
execute your new Java program from the command line, but others may not.)

What OS?
It's not a Java file (.java), but a JAR (.jar) file, right?
What's the command you used to execute it at the command line?
Did you create a "runnable" JAR?

Ok, this is my mess...
lightning@rigel5:~$ # java -jar temp.jar
lightning@rigel5:~$
...
0 0
3

I've make/install some commandline programs in the past, but my tiny experience has failed me for this java file.

Ipswitch has a java program that they provide that provides encrypted ftp transport via https. Here is the relevant passage from their guide:

"
To "install" MOVEit Xfer under Java, simply extract the contents of the MOVEit Xfer for Java archive file into a directory. To run MOVEit Xfer, you will either need to have a Java runtime executable in your command-line "executable path" or explicitly provide a path to that executable in the command line.
"

OK, the folder contains a xfer.jar file, some example .bat files and the html/support for their help guide.

Seeing as it's a .jar and not a .java file makes me think I could drop it in my /local/ folder.

I believe /local is in my PATH, but I'm finding no java love.

I had thought the .jar was executable, but I'm showing my ignorance. How would my command look like...

0 0
4
Edit Article

Two Methods:On WindowsOn MacCommunity Q&A

This wikiHow teaches you how to open and run executable JAR files on a Windows or Mac computer. JAR (Java Archive) files contain data to be used with the Java program. Most JAR files are simply containers for data that another program needs to run with Java; therefore you cannot run these files and nothing will happen when you double-click them. Similarly, most executable JAR files are downloaded as installation files to install applications or programs. Therefore, you should double check that you have the right JAR file designed for your operating system if you are having problems opening the...

0 0
5

In this tutorial, we will show you how to create a executable JAR – When you double click on it, it runs the defined main class in manifest file.

1. AWT Example

Create a simple AWT Java application, just display label and print out some funny characters ~

AwtExample.java

package com.mkyong.awt; import java.awt.Frame; import java.awt.Label; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class AwtExample { public static void main(String[] args) { Frame f = new Frame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.add(new Label("This JAR file is executable!")); f.setSize(500, 500); f.setVisible(true); } }

2. Manifest.txt

Create a manifest.txt file.

Manifest.txt

Main-Class: com.mkyong.awt.AwtExample

Uses Main-Class as the entry point of this Jar file, when you double click on this Jar file, the “AwtExample.class” main()...

0 0
6
Hello everyone

I've downloaded an executable .jar file from the internet and i would like to run it, but when i select open with other application, the java 7 runtime environment isn't in the list of programs. When i head to http://java.com/en/download/installed.jsp? (to detect wich version of java i have) it says: You have the recommended Java installed (Version 7 Update 5). Also when i type in my terminal: java -version, it says:

java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

When i try to run it through google chrome, it downloads the file again. Does anyone know how to solve this problem?

X D face...

0 0
7

. ----MySecondJavaFile.java The manifest file should contain the details of the JAR file. It keeps the. Running an executable JAR from command-line. If you want to run a.jar java file. How to Run a.Jar Java File. Execute the following command: $>java -jar.

Creating a JAR File (The Java™ Tutorials >. Deployment > Packaging Programs in JAR Files)The basic format of the command for creating a JAR file is. The options and arguments used in this command are: The c option indicates that you want to create a JAR file. The f option indicates that you want the output to go to a file rather than to stdout.

Creating a JAR File. The basic format of the command for creating a JAR file is. you could have used this alternative command to construct the JAR file.

I know that to execute a file, I use the. command. How can I execute a.jar file from the terminal. Open a command prompt with CTRL+ALT+T; Go to your '.jar. Running JAR -Packaged Software. Your JAR file contains an...

0 0
8

How Can I Execute A Jar File From The Terminal Ask Ubuntu

I know that to execute a file, I use the . command, then the file name with a space between them. But I’m trying to execute a .jar file using the . and it does not work..

Command Line How Can I Execute A Jar File From The

But I’m trying to execute a .jar file using the . and it does not work. Ask Ubuntu help How can I execute a .jar file from the terminal..

Cant Execute A Java Jar File Via Php On Ubuntu Stack

Can’t execute a Java jar file via PHP on Ubuntu. Can’t execute jar file Ask Ubuntu Webmasters .

Linux Ubuntu Execute Jar File Stack Overflow

Linux Ubuntu execute jar file. Ask tagged linux ubuntu jar startup or ask your own and all of its subfolders and files in Linux Ubuntu Terminal? ..

Ssh Running Jar In Linux Terminal Super User

Running .jar in Linux terminal. Configure Ubuntu to run JAR file by double clicking on it . . How can I ask...

0 0
9
...
0 0
10

If it is an executable jar, then

java -jar Minecraft.jar

Not all jar-Archives contain an executable class, declared to be started in the Manifest file, but if there is, this will work.

Btw.: You don't start most programs from the shell with the dot. The dot is a shortcut for source, and it only works in the bash and some other shells, to include a script in the scope of the current session.

A compiled binary xybin is simply started with its name if it is in the path:

xybin

or, with its absolute path:

/home/foo/proj/test/xybin

or with its relative path:

proj/test/xybin

or if you happen to be in the directory of the file, with this relative path:

./xybin

The file has to be marked executable for you (see: chmod). All of the above is true for shellscripts too, but they often have an extension .sh, and you can start a shellscript by invoking the interpreter, and then it needn't be marked executable:

bash xy.sh

If you don't want to...

0 0
11

I have created an executable Java .jar file. That is to say, I properly packaged a java program inside a .jar file, including a META-INF/MANIFEST file.

(Incidentally, on most Windows machines with Java installed, .jar files are registered to run as something like javaw.exe -jar %1, so you can just double click jars that have been prepared in that way.)

I just copied the same file into Linux and tried to do the same thing.

But, when I click on that file it is just opening the jar as a zip file, rather than invoking java.

How can I configure my Linux system so that the program inside the jar executes when I double click on the jar file? That is, how can I make my system invoke something like java -jar test.jar when I double click...

0 0
12

There are two ways of making a file executable:

GUI Method:

Go to the permissions tab, then tick the box `Execute: [ ] Allow executing file as program.

Terminal / Command method:

You can either use:

cd /to/my/required/directory

Then run

chmod +x filename.extension

Or just run:

chmod +x /path/to/your/filename.extension

chmod does also have some more advanced options:

The spaces are to show that it is split up: - rwx --- ---

The first set of --- is User. The second is Group and the last is Other (anyone else)

r stands for Read, w for Write and x for eXecute.

So to allow everyone to read it, but only Group to execute and User to read and write it (but for some reason not execute) would be:

-rw- rx- r-- But this would be added to the command as:

chmod +rw-rx-r-- /path/to/file.extension

chmod also can do this in numbers. It is based on binary (I think, as it is...

0 0
13

Every Java programmer knows - or should known - that it is possible to create a runnable Java package archive (JAR), so that in order to launch an application it is enough to specify the jar file name on the Java interpreter command line along with the -jar parameter. For example:

$ java -jar helloworld.jar

There are plenty of tutorials showing how to implement this feature using Ant, Maven, Eclipse, Netbens, etc.

Anyway in its basic form, it just requires to add a MANIFEST.MF file to the jar package. The manifest must contain an entry Main-Class that specifies which is the class defining the main method for your application. For example:

$ javac HelloWorld.java $ echo Main-Class: HelloWorld > MANIFEST.MF $ jar -cvmf MANIFEST.MF helloworld.jar HelloWorld.class

But this still requires your users to invoke the Java interpreter with the -jar option. There are many reasons why it would be preferable to have your app runnable by simply invoking it on the terminal...

0 0
14

One problem with your first command is that you redirect stderr to where stdout is (if you changed the $ to a & as suggested in the comment) and then, you redirected stdout to some log file, but that does not pull along the redirected stderr. You must do it in the other order, first send stdout to where you want it to go, and then send stderr to the address stdout is at

some_cmd > some_file 2>&1 &

and then you could throw the & on to send it to the background. Jobs can be accessed with the jobs command. jobs will show you the running jobs, and number them. You could then talk about the jobs using a % followed by the number like kill %1 or so.

Also, without the & on the end you can suspend the command with Ctrlz, use the bg command to put it in the background and fg to bring it back to the foreground. In combination with the jobs command, this is powerful.

to clarify the above part about the order you write the commands. Suppose stderr is address 1002, stdout is...

0 0
15

One question that a lot of beginning programmers have is: "Now that I've created my application in the IDE, how do I get it to work from the command line outside of the IDE." Similarly, someone might ask, "How do I distribute this application to other users without having to give them the whole IDE as well?"

The answers to these questions are relatively simple, but not necessarily obvious. This document addresses those questions by taking you through the basics of using the IDE to prepare your applications for distribution and deployment. In addition, this document provides information that you might need to configure your system (or which you might need to pass on to the users of your application). We will show a few different approaches for deploying an application, so that users can access the application by:

Double-clicking the application's Java Archive (JAR) file. Calling the application from the...
0 0
16

If you know how to type in a Java command at your shell command line, and you know at least the most basic SQL commands, then you know enough to benefit from SqlTool. You can play with Java system properties, PL variables, math, and other things by just executing this sqltool-2.2.6.jar file. But SqlTool was made for JDBC, so you should download HyperSQL to have SqlTool automatically connect to a fully functional, pure Java database; or obtain a JDBC driver for any other SQL database that you have an account in.

If HyperSQL's hsqldb.jar resides in the same directory as the SqlTool jar file, then you can connect up to a HyperSQL instance from SqlTool just by specifying the JDBC URL, root account user name of SA and empty password, with the \j command. See the Switching Data Sources section below for details about \j.

This document explains how to use SqlTool, the main purpose of which...

0 0
17

In Java, you can use Runtime.getRuntime().exec to execute external shell command :

p = Runtime.getRuntime().exec("host -t a " + domain); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine())!= null) { sb.append(line + "\n"); }

1. PING example

Classical example to execute the ping command and print out its output.

ExecuteShellComand.java

package com.mkyong.shell; import java.io.BufferedReader; import java.io.InputStreamReader; public class ExecuteShellComand { public static void main(String[] args) { ExecuteShellComand obj = new ExecuteShellComand(); String domainName = "google.com"; //in mac oxs String command = "ping -c 3 " + domainName; //in windows //String command = "ping -n 3 " + domainName; String output = obj.executeCommand(command); System.out.println(output); } private String executeCommand(String...
0 0