88540

NoClassDefFoundError spring boot maven

Question:

Im programming a REST API with spring boot which uses some external libraries which are included via dependency in my pom.xml. If i start the project in IntelliJ via <strong>mvn spring-boot:run</strong> everything works just fine but if i try to package everything into a jar via <strong>mvn package</strong> all external dependecy calsses are missing except the ones of spring-boot. However, the corresponding jarfiles are copied into the lib folder of the jar. So if i Start the jar everything works just fine (answering for getRequests etc.) But as soon as i want to initialize a variable of type <strong><em>FFmpegFrameGrabber</em></strong> (which is from bytedeco) i get a <strong><em>NoClassDefFoundError</em></strong>

My POM looks as follows:

<?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>spring-boot-test</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.7.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>1.1</version> </dependency> </dependencies> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

The structure of the genrerated jar (part of it):<br /> jar <br /> + hello <br /> + lib <br /> + META-INF <br /> + org <br /> ----+ springframework <br /> ----+ HERE shoould be bytedeco (?) <br />

Thanks in advance

EDIT: Minimal (Not) working example

package hello; import org.bytedeco.javacv.FFmpegFrameGrabber; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; @RestController public class HelloController { @RequestMapping("/") public String index() { String path = "D:\\TestVideos\\1\\original.mp4"; FFmpegFrameGrabber frameGrabber; System.out.println("Starting Frame Grabber for: " + path); frameGrabber = new FFmpegFrameGrabber(path); try { frameGrabber.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return "Greetings from Spring Boot! Opening: " + path; } }

And the Application.java

package hello; import java.util.Arrays; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; @SpringBootApplication public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } }

This is straight from the spring boot tutorial. tanks again

Answer1:

Add the plugin below in your pom.xml <build><plugins> ... </plugins></build> section. Build the maven project and execute the jar command. This plugin will package all your dependent jars into the final executable jar.

<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.6</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin>

This page has more information on maven assembly plugin - <a href="https://maven.apache.org/plugins/maven-assembly-plugin/usage.html" rel="nofollow">https://maven.apache.org/plugins/maven-assembly-plugin/usage.html</a>

Recommend

  • Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the p
  • Trying to get Spring/Consul/Vault to work together
  • Spring boot deploy wildfly doesn't work
  • Using the maven-remote-resources-plugin and specifying the resourcesDirectory
  • Count values that satisfy a constraint and return 0 for those that don't satisfy it in SPARQL
  • Show generated SQL in toplink in eclipse
  • Select an attribute with Xpath in a XML with namespace using Powershell
  • Spring custom user details service null pointer exception
  • Maven + Surefire/Failsafe - forkMode=“perthread” is not working … a workaround?
  • After switching from Spring Boot 1.2.8 to 1.3.2 application magically stops working
  • SessionInformation expiration doesn't lead to user log out from system
  • Reading contents of a managed bean with reflection in a JSF application
  • Savon soap body problem
  • How to set default security access for a Page Type in Silverstripe?
  • PrimeFaces p:fileUpload Listener method is never invoked for mode=“simple”
  • Get Users in Group from Azure AD via Microsoft Graph
  • how to exclude java sources from a third party jar?
  • Maven, ActionBarSherlock v4 and Roboguice v2 - How do I get it to build?
  • Filtering SPARQL results by day and month
  • Regarding client side code generation from WSDL
  • How can I create one checksum of two files in Maven to use it in the name of a directory
  • How to call BeanFactoryPostProcessor.postProcessBeanFactory method when use Spring with XML configur
  • Separate ID and Class for JS and CSS
  • Feature detection of foreignObject in SVG
  • XSD with multi occurrences unordered
  • Is it possible to define rest argument in OCaml?
  • How to convert SOAP response with xsi values to json in WSO2esb
  • Jetty 9 HashLoginService
  • java inputstream
  • Read a local file using javascript
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • Calling of Constructors in a Java
  • Numpy divide by zero. Why?
  • PHP: When would you need the self:: keyword?
  • Converting MP3 duration time