Java的可执行文件 [英] executable file for java

查看:172
本文介绍了Java的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java编程的新手

我正在通过Windows平台和ubuntu平台进行尝试

在C,C ++,C#,VB.Net中,可执行文件为.exe

我想知道什么是java的可执行文件.

如果我想在我的朋友计算机上运行程序,我只会使用.jar文件?

如何使其受到保护?

如果可执行文件是.jar,那么为什么我在ubuntu中找不到可执行文件而没有扩展名或.sh以及如何制作它?

这是我的代码,我为此创建了.jar文件
它工作正常,但在Windows和ubuntu中使用java -jar database_con.jar调用JOptionpane时不起作用

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

/*
 * 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);
         }
    }
}



带有.jar文件的lib文件夹包含mysql com.mysql.jdbc.Driver
驱动程序的jar文件.
并在类库项目的jar中添加



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

推荐答案

如果目标计算机上安装了Java Runtime(JRE),则无需创建.exe文件. .jar文件绰绰有余.

您可以尝试 [ ^ ]为JAVA应用程序创建安装程序.
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.


只是为了确保您获得所有例外:

just to make sure you get all the exceptions:

catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) 

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



否则您会错过其中的一些.
您在这个问题上有什么进展吗?

保护您的代码:
您可以添加许可证: License3j [ Proguard [ ^ ]
而且,您可以添加加密狗(物理USB设备)-但这对企业来说更昂贵,而且非常昂贵: Safenet Sentinel HASP [ ^ ]

我会推荐前2种,许可和混淆.两者都是免费且易于使用的.



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.


这篇关于Java的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆