[英]How to add/reference .jar files in your project when you don't have an IDE
I am new to Java (basically a LAMP developer). 我是Java新手(基本上是LAMP开发人员)。 I got this JAVA API to parse
.pst
files and show all the inbox messages. 我有这个JAVA API来解析
.pst
文件并显示所有收件箱消息。
I tried executing a given .class
file but it throws exceptions. 我尝试执行给定的
.class
文件,但它会抛出异常。 I need to add/reference some .jar
files provided by the API. 我需要添加/引用API提供的一些
.jar
文件。
I don't have any IDE for Java yet. 我还没有任何IDE for Java。 Wikihow says
维基话说
When your Java project requires JAR libraries to function, you have to configure your project to include the libraries in its build path.
当Java项目需要JAR库运行时,您必须配置项目以在其构建路径中包含库。 Fortunately, Eclipse makes this process simple and easy to remember.
幸运的是,Eclipse使这个过程变得简单易记。 The build used here is Eclipse Java - Ganymede 3.4.0.
这里使用的构建是Eclipse Java - Ganymede 3.4.0。
So, what configuration do I have to do? 那么,我需要做什么配置? Or is it better to get Eclipse IDE?
或者更好地获得Eclipse IDE? I just have a single
.class
file to be executed. 我只有一个
.class
文件要执行。
A few other questions that I checked but could not get my answer - How to add external jar libraries to an android project from the command line 我检查了一些其他问题,但无法得到我的答案 - 如何从命令行向android项目添加外部jar库
How do I include external JARs in my own Project JAR 如何在我自己的Project JAR中包含外部JAR
You should put them on your classpath, like 你应该把它们放在你的类路径上,比如
java -classpath someJar.jar YourMainClass
And, of course, you can do the same for javac. 当然,你也可以为javac做同样的事情。
If you need to have more than one jar or directory on your classpath, you'll need to use your platform's default path separator . 如果您需要在类路径上有多个jar或目录,则需要使用平台的默认路径分隔符 。 For example, on Windows,
例如,在Windows上,
java -classpath someJar.jar;myJar.jar YourMainClass
On a side note, you might find it easier to use an IDE to manage this sort of stuff. 另外,您可能会发现使用IDE管理这类内容更容易。 I've personally used just my slightly scriptable editor and have managed fine.
我个人只使用了我的略微可编写脚本的编辑器并且管理得很好。 But it's good to know how to do this stuff by command line.
但是知道如何通过命令行完成这些工作很好。
javac -cp yourjar.jar YourClass.java
& &
java -cp yourjar.jar YourClass
You need to make all required jar available in classpath , this is how you can do it 您需要在类路径中提供所有必需的jar,这就是您可以这样做的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.