![](/img/trans.png)
[英]I was able to open a command prompt from my Java program, How to run some exe in this command prompt using java code?
[英]How to run a java code from command prompt which is using API?
我编写的代码在jar文件中使用了Twitter4J API的类。 我想通过命令提示符运行我的代码。 我该怎么办? 我试过了:
$ javac -cp [path-to-twitter4j-jars] MyCode.java
它已成功编译,但当我运行它
$ java MyCode
但它没有找到Twitter4J课程。 我在我的代码中创建了该类的实例。
有人可以帮我解决这个问题吗?
类路径是Java按包搜索fodler中的实际.class
文件的地方。
Java不会查看类路径文件夹中的JAR。
您需要将JAR文件本身放在类路径中; 不是包含它的文件夹。
(或者,您可以包含folder/*.jar
以将每个JAR放在类路径中的该文件夹中)
运行应用程序时,JAR文件仍然需要在类路径上 ,而不仅仅是在编译时。
将jar添加到classpath:
java -cp .:path/to/twitter4j/jars MyCode
文档:
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.