Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make javac find JAR files? (Eclipse can see them)

Tags:

When I'm in Eclipse my project compiles with no errors, however when I try to compile with javac it says I'm missing some packages...

I copied my compile command and some of the error text below:

javac -classpath lib/ -d bin/ src/*.java src/Cleaner.java:5: package net.sourceforge.jgeocoder does not exist src/MyUtilities.java:19: package org.apache.commons.codec.binary does not exist 

In Eclipse, I have added all the .JAR files to the build-path, and the program compiles just fine.

Why can it not find the jars when I use javac instead of the Eclipse IDE?

like image 632
theangryhornet Avatar asked Aug 24 '11 21:08

theangryhornet


People also ask

Where does Java look for JAR files?

Extension classes - Classes that use the Java Extension mechanism. These are bundled as . jar files located in the extensions directory.

How I can see what's in JAR file?

JAR files are packaged in the ZIP file format. The unzip command is a commonly used utility for working with ZIP files from the Linux command-line. Thanks to the unzip command, we can view the content of a JAR file without the JDK.

How do I make sure a JAR file open in Java?

Right-click on the JAR file. Go to “Open With Other Applications”. Select Show other applications. Select Open With OpenJDK Java X Runtime.


1 Answers

-classpath lib/ will cause javac to look for a tree of class files in lib. If you have JAR archives there, you have to use -classpath lib/*.jar - and probably use whatever escaping mechanism your CLI has on the * to make sure it reaches javac rather than being expanded by the CLI

See the javac command reference (windows).

like image 172
Michael Borgwardt Avatar answered Nov 09 '22 19:11

Michael Borgwardt