Answer the question
In order to leave comments, you need to log in
How to specify Class-Path in MANIFEST.MF maven?
Hello everyone, in general, I'm trying to build a spring application using maven in a jar. The local repository is in ~/.m2/repository.
MANIFEST.MF:
Manifest-Version: 1.0.0
Created-By: Saveli Tomak
Main-Class: App
Class-Path: /home/saveli/.m2/repository
...
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
</dependencies>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${dir.resources}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
...
java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
Answer the question
In order to leave comments, you need to log in
<plugins>
<!--Настройка компиляции проекта-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!--Копирование зависимотей в папку lib/-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<configuration>
<!--Все зависимости которые нужны для работы твоего приложения будут лежать здесь-->
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<!--Если надо конфигурировать манифест, то здесь-->
<manifest>
<addClasspath>true</addClasspath>
<!--путь к зависимостям относительно запускаемого jar файла-->
<!--ВСЕ ЗАВИСИМОСТИ ДОЛЖНЫ БУДУТ ПОСТАВЛЯТЬСЯ С ТВОИМ jar приложением. -->
<classpathPrefix>lib/</classpathPrefix>
<classpathLayoutType>simple</classpathLayoutType>
<mainClass>main.Main</mainClass>
</manifest>
<!--<manifestEntries>-->
<!--<Rsrc-Class-Path>${}</Rsrc-Class-Path>-->
<!--</manifestEntries>-->
</archive>
</configuration>
</plugin>
</plugins>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question