简体   繁体   English

如何让 Eclipse 包含第三方库

[英]How to make Eclipse include third party libraries

在此处输入图片说明

在此处输入图片说明

classpath类路径

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry exported="true" kind="lib" path="lib/jsoup-1.7.2.jar"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

I get the following error:我收到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: gSportsParser (wrong
name: gSportsParser/gSportsParser)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

which is due to java not being able to find the Jsoup jar.这是由于java无法找到Jsoup jar。 I have looked up this problem and I've tried editing the build path, putting the jsoup in the same directory as the .class and in a subdirectory of the directory of class (/lib) to no avail.我查过这个问题,我尝试编辑构建路径,将 jsoup 放在与 .class 相同的目录中,并放在类目录 (/lib) 的子目录中,但无济于事。 How do I make Java realize jsoup is there?我如何让 Java 意识到存在 jsoup?

In Eclipse (the same as using javac to compile and java or javaw to run), the build classpath is separate from the runtime classpath. 在Eclipse中(与使用javac进行编译以及使用java或javaw进行运行相同),构建类路径与运行时类路径是分开的。 Adding JARs to your build classpath does not necessarily add them to the runtime classpath of your program/app. 将JAR添加到构建类路径中并不一定将它们添加到程序/应用程序的运行时类路径中。

You didn't mention how you're running your app, but in Eclipse there is the concept of Launch Configurations that are used to configure the runtime for a program. 您没有提到如何运行应用程序,但是在Eclipse中,有启动配置的概念,用于配置程序的运行时。 A Launch Configuration is created when you do something like right-click on a project or class and choose Run As... You can also view and edit the launch configurations from the toolbar buttons for Run and Debug. 当您在项目或类上单击鼠标右键,然后选择“运行方式...”时,就会创建启动配置。您还可以从工具栏上的“运行”和“调试”按钮查看和编辑启动配置。 The bottom line is that Launch Configurations have a classpath and it must included all the projects and libraries (JARs) that your code uses. 最重要的是,启动配置具有类路径,并且必须包含代码使用的所有项目和库(JAR)。

You need to include the jar file in your classpath.您需要在类路径中包含 jar 文件。 If you use eclipse, after adding the jar file如果使用eclipse,添加jar文件后在此处输入图片说明 , you should have something like the attached illustration ,你应该有像所附插图一样的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM