I am newbie to maven and i am having some trouble building my project. i have added the log4j dependency to the pom file
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>runtime</scope>
</dependency>
and i am using it in a normal use in one of my classes
import org.apache.log4j.Logger;
public class ConnectionPoolImpl implements Runnable, ConnectionPool {
static Logger logger = Logger.getLogger(ConnectionPoolImpl.class);
the compilation went well until i have used the mvn clean command. now when i try to build my project using mvn compile i am getting:
[INFO] Compiling 2 source files to C:\Temp\cp\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \Temp\cp\src\main\java\com\opower\connectionpool\ConnectionPoolImpl.java
:[9,23] package org.apache.log4j does not exist
[ERROR] \Temp\cp\src\main\java\com\opower\connectionpool\ConnectionPoolImpl.java
:[19,9] cannot find symbol
symbol : class Logger
location: class com.opower.connectionpool.ConnectionPoolImpl
[ERROR] \Temp\cp\src\main\java\com\opower\connectionpool\ConnectionPoolImpl.java
:[19,25] cannot find symbol
symbol : variable Logger
location: class com.opower.connectionpool.ConnectionPoolImpl
[INFO] 3 errors
any ideas what i am doing wrong?
I am not a Maven
specialist, but the log4j
scope should be compile
instead of runtime
. Please correct me if I am wrong.
From maven doc,
runtime - this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
If you had the scope as runtime
, the original intention likely was to use SLF4J or somesuch instead. Very easy to import the wrong namespace for Logger
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With