Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

shell script to run jar file

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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
 
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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: 65041
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, surely your .sh file should start with #! rather than ! shouldn't it?
 
Tim Holloway
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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:
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Java Code Review and Psychology
https://coderanch.com/t/714798/java/Java-Code-Review-Psychology
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!