javac: error: package does not exist
The compiler cannot see the jar. Put it on the classpath, or let Maven or Gradle manage scopes so compile time and runtime agree on what exists.

Introduction & Quick Summary
A single Java file that compiles in the IDE fails from the terminal:
Main.java:3: error: package org.apache.commons.lang3 does not exist
import org.apache.commons.lang3.StringUtils;
^
1 errorQuick answer: the compiler cannot see the jar. Put it on the classpath.
javac -cp "lib/*" -d out $(find src -name '*.java')
java -cp "out:lib/*" Mainpackage does not exist is an import error, and it is reported before symbol resolution. javac read import org.apache.commons.lang3.StringUtils;, looked for a package named org.apache.commons.lang3 on the compile classpath and the source path, and found nothing. The ^ sits under the imported type name because that is the token whose resolution failed.
Keeping this distinct from cannot find symbol saves time. package does not exist means the dependency is absent or invisible. cannot find symbol means the package was found but the class, method or variable inside it was not — a typo, a wrong signature or a missing import statement in an otherwise present dependency.
Core Mechanics, Signatures & Reproducible Setup
Reproduce it without any build tool:
mkdir -p demo/src/com/example && cd demo
cat > src/com/example/App.java <<'JAVA'
package com.example;
import org.apache.commons.lang3.StringUtils;
public class App {
public static void main(String[] args) {
System.out.println(StringUtils.capitalize("hello"));
}
}
JAVA
javac -d out src/com/example/App.java
# error: package org.apache.commons.lang3 does not existNow download the jar, put it in lib/ and compile again:
curl -sLO https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.17.0/commons-lang3-3.17.0.jar
mkdir -p lib && mv commons-lang3-3.17.0.jar lib/
javac -cp "lib/*" -d out src/com/example/App.java
java -cp "out:lib/*" com.example.AppThe classpath is a design decision, not a detail. Every entry is a directory containing package folders or a jar file; lib/* expands to every jar in lib, and lib alone would make javac look for a file named lib/org/apache/.... Entry order matters when two jars contain the same class: the first match wins, silently.
| Situation | javac's answer | What it means |
|---|---|---|
| jar not on the classpath | package X does not exist | add it with -cp |
| jar on the classpath, class renamed | cannot find symbol at the usage | wrong artifact version |
| wrong package line in the file | package X does not exist for a sibling import | fix the declared package |
dependency marked provided | compiles, fails at runtime | NoClassDefFoundError |
| dependency only in test scope | compiles in tests, not in main | move the scope |
Key Comparison Table
Classpath syntax differs by shell and OS, and a wrong separator is the second most common cause after a missing jar:
| Form | Separator | Expands jars | Where it applies |
|---|---|---|---|
-cp lib/a.jar:lib/b.jar | : | no | Linux, macOS |
-cp "lib/a.jar;lib/b.jar" | ; | no | Windows |
-cp "lib/*" | none | yes | every platform, inside quotes |
CLASSPATH=lib/* env | platform | yes | inherited by javac and java |
-cp out:lib/* | platform | yes | running a built program |
manifest Class-Path | spaces | no | executable jars |
The build tools express the same thing, and each has a scope that decides whether a dependency reaches the compiler:
| Tool and scope | On compile classpath | On runtime classpath | Typical use |
|---|---|---|---|
Maven compile | yes | yes | libraries used in main code |
Maven provided | yes | no | servlet API, JDK-provided APIs |
Maven runtime | no | yes | JDBC drivers |
Maven test | tests only | tests only | JUnit, Mockito |
Gradle implementation | yes | yes | default choice |
Gradle compileOnly | yes | no | annotations, provided APIs |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Maven projects: ask the build, not the terminal
mvn -q dependency:tree -Dincludes=org.apache.commons
mvn -q dependency:tree -Dscope=compile | grep commons
mvn -q -X compile | grep -i classpath | head -3If the dependency does not appear in the tree, the pom.xml is wrong. If it appears with scope provided or test, the compiler sees it but the runtime will not. mvn dependency:tree is faster than reading a 300-line pom, and filtering its output with the regex tester turns a long tree into the two lines that matter. A dependency that arrives transitively and disappears after an upgrade usually means someone added an <exclusions> block upstream; declaring it explicitly at the version you need is the stable fix.
2. Gradle projects: implementation versus api
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
compileOnly("org.projectlombok:lombok:1.18.34")
annotationProcessor("org.projectlombok:lombok:1.18.34")
}In a multi-module build, implementation is not exported to consumer modules; code in module B that imports a class from module A's implementation dependency fails with package does not exist even though A compiles. Either the class should not be part of A's public API, or the dependency belongs in api. Lombok needs both lines: compileOnly for the annotations and annotationProcessor to generate code. Missing the processor produces cannot find symbol for generated getters, which looks unrelated.
3. javac directly: quoting, wildcards and stale output
# wrong: the shell expands lib/* into separate arguments
javac -cp lib/* -d out src/App.java
# right: quoted, so javac expands it
javac -cp "lib/*" -d out src/App.java
# compiling a tree
find src -name '*.java' > sources.txt
javac -cp "lib/*" -d out @sources.txt@sources.txt avoids the "argument list too long" limit on large trees. Also delete out/ when the classpath changed: javac reuses class files it finds on the classpath, and a stale out directory can hide a missing dependency until a clean build in CI.
4. Module path and module-info.java
A modular project that puts its dependencies on the classpath instead of the module path gets import errors that look like missing jars:
javac --module-path "lib" --add-modules org.apache.commons.lang3 -d out \
src/main/java/module-info.java src/main/java/com/example/App.javamodule com.example.app {
requires org.apache.commons.lang3;
exports com.example.app;
}Three related messages follow from the same setup: package org.apache.commons.lang3 is not visible (module not required), module not found: org.apache.commons.lang3 (jar not on the module path) and package does not exist (jar on neither path). A plain jar without module-info.class becomes an automatic module named after its file name, so commons-lang3-3.17.0.jar is org.apache.commons.lang3 only because the jar declares Automatic-Module-Name; otherwise the name would be derived from the file name with dashes turned into dots.
5. javax to jakarta, and split packages
The Jakarta EE rename moves every package: javax.servlet.http.HttpServlet became jakarta.servlet.http.HttpServlet. A project that upgrades the API jar but keeps old imports gets package javax.servlet.http does not exist, and the fix is a coordinated change of imports, the server version and the dependency version. Split packages — two jars contributing to the same package — are legal on the classpath and illegal on the module path, so a library set that compiles today can fail the moment module-info.java is added.
6. IDE works, CLI fails (and the reverse)
The IDE builds its own classpath from the project model, so the two environments disagree whenever the model and the files do. Check which:
# what classpath does the build tool actually use?
mvn -q help:evaluate -Dexpression=project.build.outputDirectory -DforceStdout
ls target/classes target/dependency 2>/dev/null | headThe common cases are an IDE-only library reference pointing at an absolute path on one machine, a source folder not registered as a source root, and an annotation processor configured only in the IDE. Verify a downloaded jar before trusting it — sha256sum it and compare with the checksum from Maven Central using the hash tool; a truncated jar produces exactly this error.
Common Compilation/Runtime Mistakes & Version Gotchas
Setting -cp and expecting CLASSPATH to still apply. The flag replaces the environment variable rather than extending it. Repeat every entry in the flag.
Compiling with one version and running with another. --release 17 compiles against the 17 API; running with an older JRE gives UnsupportedClassVersionError, and an older jar on the runtime classpath gives NoClassDefFoundError for a method that exists only in the newer version.
Assuming a transitive dependency is permanent. Dependencies move between artifacts; declare what you import.
Adding the jar to the IDE only. A CI build with a fresh checkout uses the pom or the build file, never the IDE metadata.
Version notes. javac has printed the package does not exist wording unchanged for two decades, but the mapping changed with JDK 9 modules: on the module path the compiler reports module not found instead. --release replaced -source/-target for API correctness from JDK 9. JDK 11 removed the EE modules from the JDK itself, which is why old code importing javax.xml.bind now fails to compile without an explicit dependency.
A durable habit. Compile with the same command CI uses, from a clean target/ or build/ directory, before pushing. The error above never survives that check.
Reference material: javac and Maven dependency mechanism.
Official references
primary documentationThe Java documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Java work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Java guides
All Java guidesSpring Boot: No qualifying bean of type available
The context could not satisfy a constructor argument. Scan boundaries, missing stereotypes, ambiguous candidates and test slices are the usual reasons.
Method Scope in Java: How Local Variables Work
Understand how variables behave inside Java methods: local variable boundaries, block scope, parameter scope, shadowing, and lifetime implications.
Java: LazyInitializationException could not initialize proxy
A lazy association was read after the session closed. Fetch it inside the transaction, use a join fetch or entity graph, or map a DTO instead.
Java: HikariPool connection is not available, request timed out
The HikariCP pool ran out of connections for the whole connectionTimeout. Read the counters, find leaks or slow queries, then size the pool.
More in Java
All Java guidesThe guides filed next to this one in Java, in library order.