Eclipse:从java classpath中的文件夹中添加所有jar [英] Eclipse: Adding all the jars from a folder in java classpath

查看:209
本文介绍了Eclipse:从java classpath中的文件夹中添加所有jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



可以使用以下命令使用命令行来完成:

  java -cplib / *my.package.Main 
pre>

但是如何从eclipse中完成?



编辑:在我的项目floder中编辑 .classpath 条目:

  ?xml version =1.0encoding =UTF-8?> 
< classpath>
< classpathentry kind =srcpath =src/>
< classpathentry kind =conpath =org.eclipse.jdt.launching.JRE_CONTAINER/>
< classpathentry kind =libpath =F:/ Program Files / Java / log4j / apache-log4j-2.0-alpha2-bin / */>
< classpathentry kind =outputpath =classes/>
< / classpath>

这里 F:/ Program Files / Java / log4j / apache-log4j- 2.0-alpha2-bin / jar 文件所在的文件夹。但是它没有起作用。



更新:似乎没有直接的方法来做到这一点。可能是最简单的解决方案将是创建一个用户库。

解决方案

而不是在项目之外使用文件夹,必要的JAR进入项目中的 lib / 文件夹。



现在,您可以选择该文件夹中的所有JAR,右键单击 - >构建路径 - >添加到构建路径。



或者,您可以定义包含所有JAR的用户库,并将该单个项目添加到项目的构建路径。



但是最好的解决方案是使用Maven。获取Eclipse的M2E插件,并将您的项目转换为Maven项目。现在,您可以使用添加依赖关系将数百万个其他项目(包括他们需要的一切)添加到您的项目中。 Maven将下载并管理您的依赖项。


Is there a way to include all the jar files within a directory in the classpath using Eclipse?

It can be done by using command line by the following command:

java -cp "lib/*" my.package.Main

But how can it be done from eclipse?

EDIT: I edited the .classpath entry in my project floder as:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/> 
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="F:/Program Files/Java/log4j/apache-log4j-2.0-alpha2-bin/*"/>
    <classpathentry kind="output" path="classes"/>
</classpath>

Here F:/Program Files/Java/log4j/apache-log4j-2.0-alpha2-bin/ is the folder where the jar files are. But it didn't work.

UPDATE: It seems that there is no direct way to do this. And may be the easiest solution will be creating a user library.

解决方案

Instead of using a folder outside of your project, copy all necessary JARs into a lib/ folder inside of your project.

Now you can select all JARs in that folder, right click -> Build Path -> Add To Build Path.

Alternatively, you can define a "User Library" which contains all the JARs and add that single item to your project's build path.

But the best solution IMO, is to use Maven for this. Get the M2E Plugin for Eclipse and convert your project to a Maven project. Now you can use "Add Dependency" to add millions of other project (including everything they need) to your project. Maven will download and manage the dependencies for you.

这篇关于Eclipse:从java classpath中的文件夹中添加所有jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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