简体   繁体   English

在没有Java命令的情况下在Linux终端中执行Java类

[英]Executing a java class in the linux terminal without the java command

I have a java class, cs.class, that I would like to execute from the command line, just as you use any other command. 我有一个java类cs.class,我想从命令行执行该命令,就像使用其他任何命令一样。 I would like to be able to type 'cs file1' etc. Without having to use 'java cs file1'. 我希望能够输入“CS文件1”等,而无需使用的Java CS文件1“。 How can I do this? 我怎样才能做到这一点?

edit: I would also like this to work if I put my class anywhere in my path. 编辑:如果将我的课程放在自己的路径上的任何地方,我也希望此方法有效。

看来将在Linux上为您工作。

For Windows 对于Windows

Create a file named custom.cmd and add the following to it 创建一个名为custom.cmd的文件,并添加以下内容

@echo off
DOSKEY cs=java cs $*

Now 现在

right click your command prompt shortcut->properties->shortcut tab->and append the following to your target field 右键单击命令提示符快捷方式->属性->快捷方式选项卡->并将以下内容附加到目标字段

/KC:\\custom.cmd /KC:\\custom.cmd

my custom.cmd resides in C:, change the path to yours Now you can use "cs" as a command within that cmd shell. 我的custom.cmd驻留在C:中,将路径更改为您的路径现在,您可以在该cmd shell中使用“ cs”作为命令。 You can mention you filename as an argument as well as $* specifies command line arguments. 您可以提及filename作为参数,而$ *指定命令行参数。

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

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