Error: Unable to initialize main class org.example.Application java.lang.NoClassDefFoundError
Есть maven проект с зависимостями, который я собираю командой mvn clean install. Запускаю в консоли java -jar CLASSPATH ARG[0] и получаю:
Error: Unable to initialize main class org.example.Application
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
Как я понял, файл jar не видит зависимости, в частности spring-context. Гуглил, говорили об "Uber jar" и maven-shade-plugin. Я еще мало работал с плагинами и maven. Подскажите, как подцепить зависимости мэйвеном, если правильно понял, что проблема в этом. Буду благодарен любым источникам, где мог бы разузнать о своей проблеме.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>application</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>org.example.Application</start-class>
</properties>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.12.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>org.example.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>com.google.code.gson:gson</include>
<include>org.springframework:spring-context</include>
</includes>
</artifactSet>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Main class:
public class Application {
public static BlockingQueue<Order> QUEUE = new ArrayBlockingQueue<>(1000);
public static int ORDER_ID = 0;
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(Application.class);
FileHandler fileHandler = context.getBean("fileHandlerV1", FileHandlerV1.class);
fileHandler.setArgs(args);
OutputConverter converter = context.getBean("outputConverter", OutputConverter.class);
ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.submit(fileHandler::convert);
executorService.submit(converter::convertToJson);
executorService.shutdown();
}
}