外部罐子放在哪里? [英] Where to put the external jars?

查看:35
本文介绍了外部罐子放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Eclipse (3.4) 并且我的类编译时没有警告或错误.我的项目使用外部 jar 文件.

I use Eclipse (3.4) and my class compiles without warning or errors. My project uses an external jar file.

从另一个项目(不在 Eclipse 中)使用这个类时,我需要把这个外部 jar 文件放在哪里才能不得到 java.lang.NoClassDefFoundError?

Where do I need to put this external jar file in order not to get a java.lang.NoClassDefFoundError when using this class from another project (not in Eclipse)?

我可以将 jar 解压缩到项目文件夹中,但感觉不对.

I could just extract the jar into the project folder, but that does not feel right.

这个问题不是关于在 Eclipse 中导入 jars,而是在 Eclipse 之外使用它们.

this question is not about importing jars in Eclipse, but using them outside of Eclipse.

推荐答案

如果你想在你的 Eclipse 项目中包含一个 JAR 文件,你通常会在项目文件夹中创建一个 'lib' 文件夹,并将该文件放入在那里.然后您需要告诉 eclipse 将它包含在您的类路径中,以便您的代码将在 eclipse 中编译和运行.

要做到这一点:
- 进入项目的属性
- 在左侧栏中选择Java Build Path"
- 选择窗口中央部分的库"选项卡
- 单击添加 JAR 按钮 - 这将为您提供 eclipse 中的项目列表 - 展开您的项目并进入 lib 文件夹 - 您的 jar 将在那里.
- 选择 JAR,单击确定,然后再次退出属性窗口.

If you're wanting to include a JAR file to your Eclipse project, you would generally create a 'lib' folder inside the project folder, and put the file in there. You then need to tell eclipse to include it in your class path so your code will compile and run inside eclipse.

To do that:
- Go into the properties of your project
- Select 'Java Build Path' in the left hand column
- Select the 'Libraries' tab in the centre part of the window
- Click the Add JARs button - this will give you a list of your projects in eclipse - expand your project and into the lib folder - your jar will be there.
- Select the JAR, click OK, and OK again out of the properties window.

您的代码现在将编译并运行.

Your code will now compile and run.

这篇关于外部罐子放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆