Results 1 to 2 of 2
  1. #1
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default Execuatble jar file

    Hello,

    i have created this code:
    Java Code:
    package javaapplication6;
    import java.util.*;
    import java.io.*;
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            int radius;
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Please enter the radius of your circle");
                radius=Integer.parseInt(br.readLine());
                System.out.println("The radius you entered was: "+radius);
                double area=Math.PI*radius*radius;
                System.out.println("Calculating your circle area... please wait...");
                System.out.println("The area of your circle is:"+area);
            }
            catch (IOException ioe) {
                System.out.println("An error has occured:"+ioe);
            }
            
    
        }
        }
    when i run it in Netbeans it works fine, i wanted to sent it to a friend because i was proud of it.

    so i built the projects and tried to run the .JAR file but it doesn't do anything?
    anyone know why?
    heres my jar file:JavaApplication6.zip

    thanks in advance, Jesse
    Beginner in Java Programming, Please don't trust my anwsers blind please :D

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by coltragon View Post
    Hello,

    i have created this code:
    Java Code:
    package javaapplication6;
    import java.util.*;
    import java.io.*;
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            int radius;
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Please enter the radius of your circle");
                radius=Integer.parseInt(br.readLine());
                System.out.println("The radius you entered was: "+radius);
                double area=Math.PI*radius*radius;
                System.out.println("Calculating your circle area... please wait...");
                System.out.println("The area of your circle is:"+area);
            }
            catch (IOException ioe) {
                System.out.println("An error has occured:"+ioe);
            }
            
    
        }
        }
    when i run it in Netbeans it works fine, i wanted to sent it to a friend because i was proud of it.

    so i built the projects and tried to run the .JAR file but it doesn't do anything?
    anyone know why?
    heres my jar file:JavaApplication6.zip

    thanks in advance, Jesse
    You can run code from a .jar file in two ways:

    1) mention your .jar file in your classpath variable and run the class javaapplication6.Main as you always do.

    2) double click on your .jar file (this is what most people want to do). If there is a system association between a .jar extension and the java(w) program, the jvm tries to run a class from that .jar file; it has to know which class to run; you mention that class in the 'manifest' file entry in the .jar. Here's an example:

    Java Code:
    Manifest-Version: 1.0
    Created-By: coltragon
    Main-Class: javaapplication6.Main
    Built-By: coltragon
    Name: Circle Application
    Specification-Title: Circle Application
    Specification-Version: 1.0
    Specification-Vendor: coltragon
    Implementation-Title: Circle Application
    Implementation-Version: 1.0
    Implementation-Vendor: coltragon
    Many of the lines above aren't necessary. Check the documentation for the jar utility how to add this manifest file to your jar.

    kind regards,

    Jos

    ps. you need to run your program with the 'java' command, not the 'javaw' command because your program needs a console.
    Last edited by JosAH; 01-17-2010 at 10:31 AM.

Similar Threads

  1. retain value of input type file in a jsp file while being dynamically generated
    By nidhi c in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 02:21 AM
  2. Replies: 2
    Last Post: 04-07-2009, 06:25 AM
  3. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  4. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •