Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import JARs and Packages in Java

Tags:

I'm relatively new to Java. I've been using Eclipse to do some work but I want to get back to basics and just use a text editor in conjunction with the JDK. The problem I'm now having is that Eclipse and other IDEs hide away a lot of fundamental stuff which is very important to know and fully understand. This is what I'm trying to do:

  • I've created a directory called "C:\Java Projects", under which I have created 3 sub-folders, Project1, Project2 and SharedJars. Project1 and Project2 both have SubDirs like classes and source. The Poject1 source .java files live in "c:\Java Projects\Project1\source\com\myApp"

  • Both Project1 and Project2 are packages which use the Log4J JAR which lives in the SharedJars folder. In the Eclipse world, I could set something which told Eclipse which JARs my Project will use and then do something like import org.apache.log4j.Logger which worked fine. But I'm struggling to get this working.

  • I've set the CLASSPATH environment variable like "C:\Java Projects\SharedJars\log4j-1.2.15.jar"

  • I then do the following:

    cd Project1\source
    javac -d ..\classes com\myApp\*

  • This produces a whole bunch of related errors like

Picked up _JAVA_OPTIONS: -Duser.home="C:\Java Projects"
com\myApp\Monitor.java:11: cannot find symbol
symbol : class Logger
location: class com.myApp.Monitor
private static Logger LOG;

Some questions: 1) Do i still need to import org.apache.log4j.Logger? 2) If so, what determines the FQDN of the package? 3) Do I need to be in a specific directory in order to run javac? Currently i'm going into the source directory of Project1 (the java/bin is in my PATH already)

Sorry for these silly questions. I've trawled through so many websites but many do not cover the very basics. I hope this makes sense.

Rgds John