How to import external jars in command line or Atom?

时间:2016-07-11 20:07:58

标签: java atom-editor

I have been using IntelliJ to run my java programs that require some external jars. I also learned that if I want to compile and run my program from the command line I should do the following:

java -classpath someJar.jar YourMainClass

or for many libraries:

java -classpath someJar.jar;myJar.jar YourMainClass

However, while placed in the src folder where my class it doesn't seem to find my class. I also like using the Atom text editor but I don't know any package that can import external libraries like an IDE does. So how do I do it in Atom or in cmd in Windows 10? I am kind of a newbie to java dev outisde my beloved IDE, so I would really appreciate some help.

1 个答案:

答案 0 :(得分:0)

如果您使用的是Windows系统,请尝试使用cmd中的以下命令进行编译(使用jar):

javac -cp .;jar-name.jar *.java

使用jar运行命令:

java -cp .;jar-name.jar JavaCodeName

如果您使用的是Unix系统,那么可以尝试以下方法在终端中进行编译:

javac -cp jar-name.jar:. *.java

运行它使用:

java -cp jar-name.jar:. JavaCodeName

我对Atom不太熟悉所以我不知道是否有附件来执行此操作,但它应该适用于终端/命令提示符。