简体   繁体   English

将Java程序转换为Linux上的可执行文件

[英]converting java program to an executable on linux

I built a java program that consists of 2 files. 我建立了一个由2个文件组成的Java程序。 The one that contains the main is SnortMonitor.java and it uses Database.java to connect to the database and run a query. 包含主要内容的是SnortMonitor.java ,它使用Database.java连接到数据库并运行查询。 I migrated it from my windows machine to the linux machine where it needs to be. 我将其从Windows计算机迁移到需要安装的Linux计算机。 I am able to compile it and run it just fine on both machines. 我能够编译它并在两台机器上正常运行。

My ultimate goal, which is my next step, is finding a way to make this into an executable with will constantly run on this linux machine. 我的最终目标是我的下一步,这是找到一种使之成为可执行文件的方法,该方法将始终在此linux计算机上运行。 The program is designed to scan each record of a database and send certain information to another machine, I need it to run constantly so that it is constantly sending this information to this other machine, or something like every 3-5 seconds. 该程序旨在扫描数据库的每条记录,并将某些信息发送到另一台计算机,我需要它不断运行,以便它不断地将此信息发送到另一台计算机,或每3-5秒发送一次。

One Footnote: For some reason that is beyond my knowledge, I ended up with SnortMonitor.java , Database.java , SnortMonitor.class and Database.class once I finished compiling and running on linux, I'm not sure if this makes a difference, I'm very new to linux. 一个脚注:由于我无法理解的某种原因,我在完成编译并在linux上运行后最终得到了SnortMonitor.javaDatabase.javaSnortMonitor.classDatabase.class ,我不确定这是否SnortMonitor.class ,我是Linux的新手。

You have two options: 您有两种选择:

  1. Create a start-up script, such as a .sh bash script for example, that launches your java application. 创建一个启动脚本,例如.sh bash脚本,以启动Java应用程序。 See Tomcat startup script for an example. 有关示例,请参见Tomcat启动脚本
  2. Use GCJ to compile it to machine code, but your application loses portability. 使用GCJ将其编译为机器代码,但是您的应用程序失去了可移植性。

Personally I prefer the first option, but choose what is right for you. 就我个人而言,我更喜欢第一种选择,但是选择适合您的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM