How do I add jar files to the Classpath? [closed]

别说谁变了你拦得住时间么 提交于 2019-12-17 20:07:08

问题


I'm on Windows and I've tried the -classpath under javac to no avail. Also tried moving the jar to the src directory, but java file still won't compile. Trying to do a simple import of httpclient in the script.

   import org.apache.http.client.*;

回答1:


  1. Install your JDK and leave it alone. Do not copy .jar files into your JDK folders!

  2. I'd recommend getting an IDE like Eclipse or Netbeans, if you don't already have one.

  3. I would set up a new project, create or import your source, and set a class path for the project.

  4. If that doesn't work, please tell us:

    a) your OS and version

    b) your JDK and version

    c) your IDE

    d) cut/paste the EXACT error message

    e) cut/paste the relevant code




回答2:


The -classpath command line argument (to both java and javac) expect that you will list specific JAR files (and/or "exploded" directories containing class files). This is unlike the Windows/UNIX PATH environment variable which just lists directories containing executables.

So for example, if you want to compile com.example.Foo that depends on lib/bar.jar you might use the following incantation:

javac -classpath lib/bar.jar com/example/Foo.java

But my guess is that you are also getting a specific error message, and knowing that error message would be useful in helping you further.



来源:https://stackoverflow.com/questions/10386869/how-do-i-add-jar-files-to-the-classpath

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!