Click here to Skip to main content
Sign Up to vote bad
good
See more: JavaLinuxUbuntu
i have Netbeans 7 over ubuntu 12.04
i tried to write my first java application and this is my code
 
package first_pro;
import java.io.*;
 
/**
 *
 * @author amir
 */
public class First_pro
{
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {
        byte [] name=new byte[100];
        String thename="";
       System.out.println("Enter your name:");
       System.in.read(name);
       for(int i=0;i<100;i++)
       {
           if(name[i]==10)
           {
               break;
           }
           else
           {
               thename+=(char)name[i];
           }
           
       }
       if(thename.equals("amir"))
       {
           System.out.print("the enter name is right it is "+thename+"\n");
           
       }
       else
       {
           System.out.print("the enter name is wrong it is "+thename+"\n");
       }
    }
}
 
 
i created the jar file
 
when i tried to double click on it(i made it to run by default using open jdk java runtime 6)
 
nothing happened
 
when i tried open jdk 7 also nothing happen
 
i run the jdk using terminal and it run good
 
how can i run my jar file using openjdk by double click it ?
Posted 30 May '12 - 1:40


1 solution

I don't think double-click works well with Java classes owing to the way it expects to read the pathname to the object file. Your class needs to be executed from the directory above the location of the class file with a command of the form:
java first_pro.First_pro
If the final object is a jar file then it needs to be
java -jar <name of jar file>
  Permalink  
Comments
Manfred R. Bihy - 30 May '12 - 9:07
Fixed the trailing </name ... > tag by replacing < with &lt; and > with &gt;. Cheers!
Richard MacCutchan - 30 May '12 - 9:10
Corrected it to what I originally wrote.
amir tarek - 30 May '12 - 9:07
so i am in right way? .jar from netbeans like .exe from microsoft visual studio?>
Richard MacCutchan - 30 May '12 - 9:11
No, nothing like. JAR files are Java archives and can only be run from the JDK by being invoked with a java command as I showed above.
amir tarek - 30 May '12 - 9:20
i know i know i want to ask the executable file from java is .jar? or another thing?
Richard MacCutchan - 30 May '12 - 10:05
Java does not have executables as such. The Java compiler (javac) converts source files into class files, which can be run stand-alone by invoking the java command. Class files may also be combined with other class files to create a Java archive, or jar file which can be invoked with the java command. In all cases the actual executable file is java which reads, interprets and executes the Java classes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,040
2 CPallini 3,432
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid