jeudi 12 mars 2015

Why is it that only this Java import statement for Log4j works, but not the other one?



I'm curious about how Java import works. For example, I just ran this sample log4j code, and it did not compile :



import org.apache.log4j.Logger;

import java.io.*;
import java.sql.SQLException;
import java.util.*;



public class log4jExample{
/* Get actual class name to be printed on */
static Logger log = Logger.getLogger(
log4jExample.class.getName());

public static void main(String[] args)
throws IOException,SQLException{

log.debug("Hello this is an debug message");
log.info("Hello this is an info message");
}
}


It gives this error :



3 errors found:
File: C:\Users\adel\Desktop\various_topics\new_Java_Code\log4jExample.java [line: 1]
Error: package org.apache.log4j does not exist
File: C:\Users\adel\Desktop\various_topics\new_Java_Code\log4jExample.java [line: 13]
Error: cannot find symbol
symbol: class Logger
location: class log4jExample
File: C:\Users\adel\Desktop\various_topics\new_Java_Code\log4jExample.java [line: 13]
Error: cannot find symbol
symbol: variable Logger
location: class log4jExample


But then I had another class, which has an import like this :



import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Level;

public class HelloWorldLog4J {


And this one works fine. I'm just curious , where does Java actually find the those imported libraries? thanks




Aucun commentaire:

Enregistrer un commentaire