简体   繁体   English

Linux中的Java Jar文件SoftLink

[英]Java Jar file SoftLink in Linux

I have created a jar file , it reads from standard input and print them out to the standard output. 我创建了一个jar文件,它从标准输入读取并将它们打印到标准输出。

Below is how you can use the app: 以下是如何使用该应用程序:

cat /ephemeral/test/input | java -jar /ephemeral/test/Hello.jar >> /ephemeral/test/output

I am wondering is it possible to add my Hello.jar to be a Linux Command, let's say -hello-: 我想知道是否有可能将我的Hello.jar添加为Linux命令,让我们说-hello-:

So next time I could just do something like: 所以下次我可以做一些像:

hello /ephemeral/test/input /ephemeral/test/output

I am not that much familiar with Linux Soft Link and Java, so any help or information would be appricated! 我对Linux Soft Link和Java不太熟悉,所以任何帮助或信息都会被批评!

UPDATE: thanks for reno's inspiring answer, I put the cat ... | 更新:感谢里诺的鼓舞人心的回答,我把猫... | .. >> .. into a shell script hello.sh. .. >> ..进入shell脚本hello.sh。 Now I can do something like: 现在我可以这样做:

./hello.sh /inputpath/input outputpath/output

(Note: you should not use $0, $0 is actually the name the file itself instead of input arguments) (注意:你不应该使用$ 0,$ 0实际上是文件本身的名称而不是输入参数)

Now, the last question is how could you access the shell script EVERYWHERE, like how you call basic shell cmds: ls..cat..echo.. 现在,最后一个问题是如何在任何地方访问shell脚本,就像你调用基本的shell cmd:ls..cat..echo ..

I have read a tutorial described exactly what I want(reach to the end of the tutorial directly): 我读了教程正是我想要的描述(达到本教程的最后直接):

  1. I did add the path of the directory where the hello.sh exists into the path variable. 我确实将hello.sh所在目录的路径添加到路径变量中。
  2. I created a bin folder which is like mkdir /home/ubuntu/bin and put my shell script there. 我创建了一个bin文件夹,就像mkdir / home / ubuntu / bin一样,并将我的shell脚本放在那里。 However, I still have problem do what the author described: 但是,我仍然有问题做作者所描述的:

    hello input output (in my case) 你好输入输出(在我的情况下)

Does anyone know what is going wrong here? 有谁知道这里出了什么问题?

执行此操作的方法是编写包含必要的java -jar命令的shell脚本(通常为hello.sh )。

you can write a shell script say test.sh and copy your code to test.sh 你可以写一个shell脚本说test.sh并将你的代码复制到test.sh

!/bin/bash !/斌/庆典

cat $0 | 猫$ 0 | java -jar /ephemeral/test/Hello.jar >> $1 java -jar /ephemeral/test/Hello.jar >> $ 1

and execute the script by passing your input and output file name something like this: 并通过传递输入和输出文件名来执行脚本,如下所示:

test.sh /ephemeral/test/input /ephemeral/test/output test.sh / ephemeral / test / input / ephemeral / test / output

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

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