There is a project maven, it is compiled in Intelli Idea. After that, I compile it with maven and create a jar file. Which at start (in the console) gives an error:
java.lang.NoClassDefFoundError: org / apache / log4j / Logger at
Main. (Main.java:10)
Swears on logging, works without logging and writes what I need.
XML file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Time</groupId> <artifactId>GreetTime</artifactId> <packaging>jar</packaging> <version>1.0</version> <name>GreetJar</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.6</jdk.version> <log4j.version>1.2.12</log4j.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <mainClass>Main</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> </dependencies> <pluginRepositories> <pluginRepository> <id>onejar-maven-plugin.googlecode.com</id> <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url> </pluginRepository> </pluginRepositories> Program Code:
import org.apache.log4j.Logger; import java.util.ResourceBundle; /** * Created by Alex on 07.09.2016. */ public class Main { public static Logger log = Logger.getLogger(Main.class); public static void main(String[] args) { log.info("Create Greet object"); Greet gr = new Greet(); gr.getLocale(); gr.gethours(); ResourceBundle bundle = ResourceBundle.getBundle("Bundle", gr.myLocale); log.info("Switch language"); gr.showMessage(bundle); log.info("Conclusion greetings"); log.info("Terminate program"); } } Judging from what I found on the Internet, I need to correct the haze in the mainfest and somehow create lo4j.jar, it remains to understand how.