Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Linux Ubuntu
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
{
 
<pre>
/**
 * @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&lt;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 2:40am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
v3
Comments
Manfred R. Bihy at 30-May-12 9:07am
   
Fixed the trailing </name ... > tag by replacing < with &lt; and > with &gt;.

Cheers!
Richard MacCutchan at 30-May-12 9:10am
   
Corrected it to what I originally wrote.
amir tarek at 30-May-12 9:07am
   
so i am in right way?

.jar from netbeans like .exe from microsoft visual studio?>
Richard MacCutchan at 30-May-12 9:11am
   
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 at 30-May-12 9:20am
   
i know i know
i want to ask the executable file from java is .jar? or another thing?
Richard MacCutchan at 30-May-12 10:05am
   
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
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 310
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 30 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100