• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating a jar file  RSS feed

 
Marcello Lippi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm very new to java, tried to write my first program and it works.

I typed in notepad:

//A Very Simple Example
class ExampleProgram {
public static void main(String[] args) {
System.out.println("I'm a Simple Program");
}
}

saved it as ExampleProgram.java

and then compiled it using

javac ExampleProgram.java

Now I can run it:

java ExampleProgram

and it displays text "I'm a Simple Program".

Now the question is - how do I run my program without typing "java [program name]" ? I mean, I'd like rather to run it using some kind of ExampleProgram.exe but without typing "java" before program name.

So I've changed directiory to

C:\oracle\Middleware\jdk160_24\bin

created manifest file

echo Main-Class: ExampleProgram >manifest.txt

created my jar file

jar cvfm ExampleProgram.jar manifest.txt ExampleProgram.class

tried to test result by running my program

ExampleProgram.jar

(It doesn't return any result in command line).

But when I run "java ExampleProgram" it does display "I'm a Simple Program"

What I'm doing wrong now?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you firing these commands from?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcello Lippi wrote:tried to test result by running my program

ExampleProgram.jar

(It doesn't return any result in command line).


But that isn't how you run an executable jar. You have to type "java -jar ExampleProgram.jar" at the command line. Read through Oracle's JAR tutorial to see how it actually works.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!