• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

shell script to run jar file

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have jar file named as example.jar that I can execute it in CMD in windows by java -jar example.jar. I want to write a shell script that I can execute the example.jar file. I wrote this script



but there is an error


please help me.Thank you
 
Saloon Keeper
Posts: 24565
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you're trying to run the same JAR. If that message means what I think it does, the file "example.jar" doesn't have a proper manifest file in it, just one with a stub that looks like this:


The text "name of the main class" needs to be replaced with the fully-qualified class name containing the main() method. (package and classname).
 
Marshal
Posts: 74380
334
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, surely your .sh file should start with #! rather than ! shouldn't it?
 
Tim Holloway
Saloon Keeper
Posts: 24565
168
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Also, surely your .sh file should start with #! rather than ! shouldn't it?



Oh yes. A simple "!" is an attempt to use command history. The "#!" is called "shebang", which comes from "shell-bang", where "bang" is the nickname for an exclamation point, like "splat" is for an asterisk.

When you start a script file with a shebang, the first line of that script will be executed as a command. /bin/sh for generic shell, /bin/bash for the Bash shell, /bin/zsh for zshell, and non-shell commands like /usr/bin/python or /usr/bin/perl.

And yes, a 1-line script could look like this:
 
reply
    Bookmark Topic Watch Topic
  • New Topic