Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am new in java programming

i am trying it through windows platform and ubuntu platform

in c, c++, c#, VB.Net the executable file is .exe

i want to know what is the executable file for java is it .jar ?

and if i want to run my program in my friend computer i only take the .jar file?

how to make it protected?

if the executable file is .jar exactly why i find executable files in ubuntu wuth no extension or .sh and how to make it?

this my code i created the .jar file for it
it works fine but JOptionpane donot work when call it using java -jar database_con.jar in windows and ubuntu

Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database_con;
import adding.adding;
import com.mysql.jdbc.Statement;
import com.sun.corba.se.spi.orbutil.fsm.Input;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
 *
 * @author engamir
 */
public class Database_con {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        System.out.println("MySQL Connect Example.");
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "test";
        String driver = "com.mysql.jdbc.Driver";
        String userName = "root"; 
        String password = "globalamirtarek";
        com.mysql.jdbc.Statement st=null;
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url+dbName,userName,password);
            System.out.println("Connected to the database");
            st=(Statement) conn.createStatement();
            ResultSet rs;
            //st.executeUpdate("insert into name values(4,'noura')");
            st.executeUpdate("Delete from name where name_id=2");
            rs=st.executeQuery("Select* from name");
            int name_id;
            String name;
            while(rs.next())
            {
                name_id=rs.getInt("name_id");
                name=rs.getString("name");
                System.out.printf("%d    %s\n",name_id,name);
            }
            System.out.println("Disconnected from database");
            
        } 
        catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) 
        {
            System.out.println(e.getMessage());
        }
        int z=adding.add(5, 6);
         System.out.print(z);  
         z=JOptionPane.showConfirmDialog(null,"is the number of the result is 11?","The result",1);
         String name=JOptionPane.showInputDialog("what is your name?");
         if(z==0)
         {
             System.out.printf("thanks %s the result is great", name);
         }
         else if(z==1)
         {
             System.out.printf("thanks %s but the result is wrong", name);
         }
         else if(z==2)
         {
             System.out.printf("go to hell %s", name);
         }
    }
}


the lib folder with the .jar file contain the jar file of the driver of mysql com.mysql.jdbc.Driver

and the jar of the class library project adding
Posted
Updated 5-Jul-12 1:24am
v2

If Java Runtime (JRE) is installed on the target machine, you don't need to create a .exe file. A .jar file is more than enough.

You may try this to [^] create installers for JAVA apps.
 
Share this answer
 
Comments
amir tarek 5-Jul-12 6:36am    
ok now i will ask you one question i write a program that try to connect to database then retrieve data then close the connection

then use a jar class library project to add two integer number

then display option message with yes or no or cancel

i make the jar file and when i executed it using java -jar myfile.jar

it works fine but donot display the option message Joptionpane

but it works when execute it from netbeans
TorstenH. 5-Jul-12 7:02am    
does your application throw an exception? Do you have any logging in it (log4j)?
You might have to add some more stuff to the build, as only the added stuff is available for the exported JAR, but all is available inside your IDE.
amir tarek 5-Jul-12 7:25am    
i improve my question to show you my code
amir tarek 5-Jul-12 7:57am    
my application do not throw any exception
what now i must to add ?
just to make sure you get all the exceptions:

Java
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) 

catch (Exception e)
        {
            System.out.println(e.getMessage());
        }


otherwise you would miss some of them.
Do you have any progress on the problem?

to protect your code:
You can add a license: License3j[^]
You can obfuscate the code: Proguard[^]
And you can add a Dongle (physical USB-Device) - but that is more for business and quite expensive: Safenet Sentinel HASP[^]

I would recommend the first 2, license and obfuscation. Both are free and easy to use.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900