创建一个Shell脚本以在Linux上运行Java程序 [英] Create a shell script to run a Java program on Linux

查看:378
本文介绍了创建一个Shell脚本以在Linux上运行Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Java程序来同步两个目录的内容.该程序将两个目录的位置作为参数来同步它们,同步信息是将它们存储在每个目录内的JSON格式的文件中. 我有一个引用的库json-simple-1.1.1.jar

I have created a java program which syncs the contents of two directories. The program takes the location of the two directories as arguments the proceeds to sync them, the sync information is them stored in a JSON formatted file inside each directory. I have one referenced library json-simple-1.1.1.jar

我正在Windows上从eclipse运行此程序,一切正常. 我想创建一个shell脚本,以便我可以在Linux终端上通过键入sync dir1 dir2来运行它,其中sync是我的Java程序,而dir1dir2是要从当前目录同步的目录的路径

I'm running this from eclipse on windows and everything is working correctly. I want to create a shell script so that I can run this on a Linux terminal by typing sync dir1 dir2 where sync is my java program and dir1 and dir2 are the paths to the directories to synchronize from the current directory.

我对Shell脚本和Linux还是很陌生,不确定这样做是否容易或者会花费我一整天的时间.

I'm very new to shell scripts and Linux and unsure whether this is easy to do or will take me all day.

推荐答案

在/usr/bin中创建一个名为"sync"的文件,其中包含以下内容:

create a file named "sync" in /usr/bin containing the following:

java -jar {PATH TO JARFILE} $1 $2

{PATH TO JARFILE}替换为jarfile的路径

Replace {PATH TO JARFILE} with the path to the jarfile

在/usr/bin

这篇关于创建一个Shell脚本以在Linux上运行Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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