简体   繁体   English

如何在没有IDE的情况下在项目中添加/引用.jar文件

[英]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.

相关问题 如何在Eclipse IDE项目文件夹中为spring添加jar文件 - How to add jar files for spring in Eclipse IDE project folder 拥有.jar时如何写入文件 - How to write files when you have a .jar 为什么有时需要在构建路径中添加JAR,有时则不需要? - Why do you sometimes need to add a JAR to your build path and sometimes you don't? 当项目转换为可执行jar时,序列化文件不起作用? - Serialized files don't work when project is converted to executable jar? 想要在Java中使用列表文件时,如何在没有权限的情况下跳过文件? - how can skip files when you don't have permission when you want use listfiles at java? 当项目为 a.jar 或 IDE 时,如何动态访问 src/main/resources 中的文件 - How can i access files in src/main/resources dynamically when the project is a .jar or in IDE 如何将PowerMock添加到项目中? - How do you add PowerMock to your project? 如何从ArrayAdapter中删除一个没有该对象引用但又有另一个全等对象的对象? - How to remove an object from an ArrayAdapter that you don't have that object's reference but have another congruent object? 如何在类路径中添加这些文件(*.jar)? 没有任何IDE - how to add these files(*.jar) in classpath ? Without any IDE 如何手动将.jar文件添加到Java项目 - How to add .jar files to a java project manually
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM