是否可以从命令行运行Java程序而不进行编译? [英] Is it possible to run Java program from command line without compiling?

查看:65
本文介绍了是否可以从命令行运行Java程序而不进行编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组说明来创建一个Java应用程序,当从CMD行运行该应用程序时,它需要多个参数.

I have a set of instructions to create a Java application that takes multiple arguments when running the application from a CMD line.

说明如下:

因此,使用上述示例集,假设程序的main()方法位于名为JavaClassName的类中,则输出应为:

Thus, using the example set of above, assuming the main() method of your program is in a class called JavaClassName, the output should be:

$ java JavaClassName 4 7 file.csv
program output here

我的问题是:

这不是跳过编译过程吗?
他们是否会假定将Java类加载到以前从未运行过此应用程序的计算机上(或仅包含运行所需的 .java 文件的目录);运行cmd

Isn't this skipping the compile process?
Would they assume that loading the Java classes onto a computer that has never run this application before (or a directory with purely the .java files needed to run); running the cmd

$ java JavaClassName 4 7 file.csv

会输出一些东西吗?

旁注:当前,正在运行该CMD输出

Sidenote: Currently, running that CMD outputs

Error: Could not find or load main class JavaClassName

已经经历了多个SO问题和在线教程,试图使它甚至运行,但我尚未使它起作用.

Have ran through multiple SO questions and online tutorials trying to get this to even run but I have yet to get it to work.

推荐答案

您问:

这不是跳过编译过程吗?

Isn't this skipping the compile process?

绝对可以.像 java JavaClassName 4 7 file.csv 这样的命令行假定当前目录中(或在CLASSPATH中找到的某些其他目录或Zip/Jar文件中)有一个已编译的类文件"JavaClassName.class".环境变量).是的,要生成该"JavaClassName.class"类文件,必须首先使用Java编译器.

Absolutely yes. A command line like java JavaClassName 4 7 file.csv assumes that there is a compiled class file "JavaClassName.class" in the current directory (or in some other directory or Zip/Jar file found in the CLASSPATH environment variable). And yes, to produce that "JavaClassName.class" class file, you have to use a java compiler first.

这篇关于是否可以从命令行运行Java程序而不进行编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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