I am using vlcj-4.7.1 and IntelliJ. I am using the code from https://www.tutorialspoint.com/vlcj/vlcj_play.htm The code runs and plays the video when I run it inside the IDE, but when I run it using Windows Terminal, I receive:
Error: Unable to initialize main class alan.bartlett.videotester.App Caused by: java.lang.NoClassDefFoundError: uk/co/caprica/vlcj/player/component/EmbeddedMediaPlayerComponent
Any ideas how to fix this ClassNotFoundError? I have installed VLC 3.0.17.4 if that info is useful.
pom.xml
<?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>alan.bartlett.videotester</groupId>
<artifactId>video-test-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>uk.co.caprica</groupId>
<artifactId>vlcj</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<finalName>VideoPlayer</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>alan.bartlett.videotester.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
App.java
package alan.bartlett.videotester;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.net.URISyntaxException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
/**
* This example will open a window with a play button.
* pressing play will play the hardcoded mp4 video.
*/
public class App extends JFrame {
private static final long serialVersionUID = 1L;
private static final String TITLE = "My First Media Player";
// private static final String VIDEO_PATH = "C:\Als-data\asb.mp4";
private static String VIDEO_PATH = getAppPath() + "media\asb.mp4";
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
private JButton playButton;
public App(String title) {
super(title);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
System.out.println("Media Path: " + VIDEO_PATH);
}
public void initialize() {
this.setBounds(100, 100, 600, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
mediaPlayerComponent.release();
System.exit(0);
}
});
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);
JPanel controlsPane = new JPanel();
playButton = new JButton("Play");
controlsPane.add(playButton);
contentPane.add(controlsPane, BorderLayout.SOUTH);
playButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mediaPlayerComponent.mediaPlayer().controls().play();
}
});
this.setContentPane(contentPane);
this.setVisible(true);
}
public void loadVideo(String path) {
mediaPlayerComponent.mediaPlayer().media().startPaused(path);
}
public static String getAppPath() {
File pto = null;
String str = "";
try {
// pto = new File(App.class.getProtectionDomain().getCodeSource().getLocation().toURI());
pto = new File(App.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if(pto.getAbsolutePath().contains("classes")) {
str = pto.getAbsolutePath();
String toRemove = "classes";
int x = str.indexOf(toRemove);
str = str.substring(0,x) + str.substring(x+toRemove.length(),str.length());
}
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.out.println("Absolute Path: " + pto.getAbsolutePath());
System.out.println("Path : " + pto.getPath());
System.out.println("getName: " + pto.getName());
System.out.println("str: " + str);
// return pto.getAbsolutePath();
return str;
}
public static void main( String[] args ){
boolean found = new NativeDiscovery().discover();
System.out.println(found);
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
System.out.println(e);
}
App application = new App(TITLE);
application.initialize();
application.setVisible(true);
application.loadVideo(VIDEO_PATH);
}
}