To Excecute an application from jar file

Posted on 2002-06-20
Last Modified: 2013-11-23
I have a jar file (xyz.jar) with

in which a1.class is a main class having
public static void main(String[] args)

in my manifest file i have included
Main-Class: a1.class

Now the problem is how to execute this application from the jar file directly.
This jar file is in c:\abc directory
Question by:umaiyer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Expert Comment

ID: 7095356
java -jar c:\abc\JarName.jar

Author Comment

ID: 7095379
i tried with the same command

I am getting this error:

Exception in thread "main" The system cannot find the file specified
        at Method)
        at java.util.jar.JarFile.<init>(
        at java.util.jar.JarFile.<init>(

Can u just let me know what's the problem

Thanks in advance.

Expert Comment

ID: 7095388
aha - the main class should be specified as a class name - not as a file name, that contain this class:
Main-Class: a1

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Author Comment

ID: 7095594
if this jar file(jarname.jar) is dependend on another jar file (comm.jar),do i have to include that jar file name in the manifest file of jarname.jar. if so how can i do this

Accepted Solution

Venci75 earned 100 total points
ID: 7095628
yes - you need to add it to your manifest file:

Class-Path: comm.jar

Author Comment

ID: 7098434
i have included all the jar files that are required by the application which is in jarname.jar

in the Class-Path: x1.jar x2.jar etc.......

this application also uses one xml file which is outside the jar file.This application loads the contents of the xml file.
do i have to include this xml file in the manifest file. if so how to include this resource.

the problem i am facing is.......

i have jar file & xml file in
c:\abc directory
if i go to c:\abc>java -jar jarname.jar
my application displays the contents xml file

if i give the command in this fashion
c:\>java -jar "c:\abc\jarname.jar"
my application does not displays the details of xml file

how to come across this problem. is there a way to come out of this
Thanks in advance


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question