Package does not exist when package was added to classpath

Note related solutions (for example, Fatal error: cannot find java.lang package in classpath or bootclasspath ) does not work.

I get this error, but the package is imported (commons .... jar)

org.apache.commons.lang3.tuple //does not exist import org.apache.commons.lang3.tuple.MutableTriple 

Source

 import org.apache.commons.lang3.tuple.MutableTriple; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; 

Build Code:

export JAVA_HOME = / Library / Java / JavaVirtualMachines / jdk1.8.0_25.jdk / Contents / Home / Library / Java / JavaVirtualMachines / jdk 1.8.0_25.jdk / Contents / Home / bin / javac -target 1.8-source 1.8 -classpath \ "../lib/commons-lang3-3.4.jar;../lib/httpclient-4.5.jar;../lib/httpcore-4.4.1.jar;../Library/org.json-20120521.jar ; ../ Library / pdfbox-application-2.0.0-20150606.170503-1383.jar; ../ CSI /:../ Library / Common-lang3-3.4-javadoc.jar; ../ lib / pdfbox-app- 2.0.0-20150606.170503-1383-sources.jar "\ -d output \ ../ src / com / tymaf / pdf / *. java

How to solve this problem?

+6
source share
2 answers

Double check your class path. Looks like you were mixing separators ; and :

Also, instead of including jar with compiled classes (the library itself). You have included java-docs and sources , which are useless in the classpath.

 ../src/: ../lib/commons-lang3-3.4-javadoc.jar; ../lib/pdfbox-app-2.0.0-20150606.170503-1383-sources.jar 
+5
source

Here is my suggestion

How to compile and use the .jar extension

Expansion

.jar can be imported in various ways, depending on the development environment.

Here it works as the main mode from the console.

  • Download the .jar.zip library from
    http://www.java2s.com/Code/Jar/c/Downloadcommonslang333jar.htm
  • Create a folder in your working (project) directory, call it libs
  • Unzip the downloaded file and copy commons-lang3-3.3.jar to the libs working directory
  • I also created a class just for testing, name it TheNewWork.java and add 3 imports.
  • Now from your working directory c:\projects to compile:

    javac -classpath "/Projects/libs/commons-lang3-3.3.jar;" TheNewWork.java

  • And to run:

    java -classpath "/Projects/libs/commons-lang3-3.3.jar;" TheNewWork

If you have more than one .jar , just add ; for Windows and : for Linux. Btw I am using the Windows 10 cmder console and java jdk1.8.0_66. In another OS console, you may need to install .:Projects...etc instead of /Projects...etc . but the idea is the same.

UPDATE
In windows, you can set the class path, for example

 set CLASSPATH=%CLASSPATH%;C:\Projects\libs\commons-lang3-3.3.jar 

OR on Linux

 export CLASSPATH=".:/Projects/libs/commons-lang3-3.3.jar" 

Then you can run javac TheNewWork.java , but it's a personal desire to do it anyway. Some similar things can be done in other OSs.

Last, if you are lazy and don’t want to write a full command line or not create a class path, you can create a batch file with a full command line and run it this way :;

Some links:

Hope this solves your problem.

Until decision enter image description here

After decision enter image description here


NOTE
In addition, thanks to @MarkPeters, he notified me of my previous answer: adding application dependencies directly to JRE libs is not a good approach, since JRE is suitable for running only one Java application, and not for general runtime. Plus, this will complicate any deployment that the OP wants to do. lib / ext is designed to extend the core Java APIs as described here: docs.oracle.com/javase/tutorial/ext/basics/install.html . Not for normal application dependencies.

+2
source

All Articles