How to import libraries from JAR-files into a Java program using TextMate

我怕爱的太早我们不能终老 提交于 2019-12-06 04:26:26

To be able to use classes stored inside a jar file in your program, this jar file must be part of the classpath.

Read http://en.wikipedia.org/wiki/Classpath for explanations on how to set the classpath. Note that this is also true when compiling your program.

Suppose you're at the root of your source directory and you want to compile a Java file and put the class in the classes directory:

javac -d ../classes -classpath c:\foo\bar\library1.jar;c:\foo\bar\library2.jar com/foo/bar/HelloWorld.java

Now to run your class:

java -classpath ..\classes;c:\foo\bar\library1.jar;c:\foo\bar\library2.jar com.foo.bar.HelloWorld

When your program becomes bigger that 2 or three classes, you'll probably want to use a build tool like ant, gradle or maven to build your application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!