Classpath Setup
In order to run the examples provided in the documentation, you need to add the following jars to your class path:
- logback-core-${version}.jar
- logback-classic-${version}.jar
- logback-examples-${version}.jar
- slf4j-api-${slf4j.version}.jar
The logback-*.jar files are part of the logback distribution whereas slf4j-api-${slf4j.version}.jar ships with SLF4J, a separate project.
Running from the command line
Assuming your current directory is $LOGBACK_HOME/logback-examples, where $LOGBACK_HOME stands for the directory where you installed logback, you can launch the first sample application, chapters.introduction.HelloWord1 with the following command:
java -cp lib/slf4j-api-${slf4j.version}.jar;../logback-core-${version}.jar;\ ../logback-classic-${version}.jar;logback-examples-${version}.jar\ chapters.introduction.HelloWorld1
It is more convenient to set the CLASSPATH environment variable once and for all before running the examples.
The setClasspath.cmd script located in the $LOGBACK_HOME/logback-examples folder will configure the class path for the MS Windows platform. For Unix, you can use setClasspath.sh.
Please edit the script in order to adapt the LB_HOME variable to match your local environment.
Please be aware that many examples will launch Java classes along with configuration files. To access these files by using the same commands as written in the documentation, you will need to issue the commands from within the $LOGBACK_HOME/logback-examples directory.
SMTPAppender
requires
JavaMail API
SMTPAppender
related examples require the JavaMail
API version 1.4 or later. Once you download
JavaMail, you need to place mail.jar on your class
path.
GEventEvaluator
requires the
Groovy runtime
GEventEvaluator
depends on the Groovy runtime. It
was tested with Groovy version 1.7.2.
Evaluators and more
specifically JaninoEventEvaluator
require
Janino
The evaluator examples which are mostly based on
JaninoEventEvaluator
require Janino
version 2.5.10 or later. Once you have downloaded Janino, you need to
place janino.jar on your class path.
Building with an IDE
Certain logback test cases are written in Scala. Moreover, logback offers a Groovy-based configurator. If you wish to hack logback, you will probably want to import it as a project into your favorite IDE.
Building logback with IntelliJ IDEA
Assuming you have the latest version of IntelliJ IDEA installed, you need add the Scala plugin. Once you have the Scala plugin installed, you can import logback into IDEA. Select File -> New Project -> Import from external model -> Maven, then select $LOGBACK_HOME as the Root directory. The import should finish successfully in a few seconds.
Building with Eclipse
Building logback is a little trickier. Here are step by step instruction for building logback under Eclipse in 61 easy steps.
It appears that the key to building logback under Eclipse is to avoid using m2eclipse. If you have m2eclipse installed, you can disable it by removing the Maven Nature for a given project.
- Install Eclipse Indigo, aka Eclipse 3.7
- in eclipse.ini file modify the parameter "mx", i.e. change -Xmx384m to -Xmx1384m
- Select Help -> Intall new Software -> Work with http://dist.springsource.org/release/GRECLIPSE/e3.7/ and then Select "Groovy-Eclipse Feature". Installation of other plugins in particular "m2e Configurator for Groovy-Eclipse" is not necessary
- Similar to the previous steps install Scala IDE for Eclipse from http://download.scala-ide.org/releases-29/2.0.0-beta. Installation of "JDT Weaving" or "Scala IDE for Eclipse Source feature" are not necessary.
cd $LOGBACK_HOME
where $LOGBACK_HOME stands for the location where you cloned the logback project from github- In case they exist, remove .settings, .classpath, .project directories (again if any) under $LOGBACK_HOME and its sub-folders. Somehow, this step seems to be crucial.
- Run 'mvn eclipse:eclipse' in $LOGBACK_HOME
- In eclipse import the logback project: Import -> General -> Existing Prokects into Workspace, select $LOGBACK_HOME folder for the import
- add the scala nature to logback-core project: (right click on logback-core project -> Configure -> Add Scala Nature)
- remove the logback-classic/target/generated-sources/groovy-sttubs/main directory from the list of source folders (logback-classic -> project properties -> Java Build Path)
- clean all projects in Eclipse (Project -> Clean)
- Select logback-classic project and convert it to "Groovy project" (right click on logback-classic project -> Configure -> Convert Groovy to Project)
The above should also work for Helios (Eclipse 3.6). The only difference is that the Groovy-Eclipse feature needs to be installed from http://dist.springsource.org/release/GRECLIPSE/e3.6/.