I'm creating a simple project that can convert PDF files to Excel files using GroupDocs Converter. Running it in Eclipse works, but when I try to run it from cmd, errors start to pop-up on my screen. I'm not a professional informatic, I'm only an highschooler so I can't ask you to trust me when I say that the code is perfect and it works, so there it is.
package application;
import java.io.File;
import java.util.List;
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.SpreadsheetConvertOptions;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class App extends Application {
static Stage primaryStage;
static List<File> file;
static String dir;
static String pdfFileName;
static String excelFileName;
static Text filesChoosed = new Text(
"FILE SCELTI CARICATI, CLICCA IL SIMBOLO EXCEL E ASPETTA FINO A FINE CONVERSIONE.");
static Text completation = new Text("CONVERSIONE COMPLETATA.");
static VBox boxes;
/**
* Metodo start, dove lo stage viene configurato
*/
public void start(Stage primaryStage) throws Exception {
// Costruzione iniziale della scena
primaryStage.setTitle("PDF to XLSX Convertor");
Rectangle pdfLogo = new Rectangle(110, 110);
Rectangle buttonConversion = new Rectangle(110, 110);
pdfLogo.setFill(new ImagePattern(new Image(
"https://th.bing.com/th/id/R.dd78555980adf25273aee54a1c021ddb?rik=FQVw%2bGWpZgJ18g&pid=ImgRaw&r=0")));
buttonConversion.setFill(
new ImagePattern(new Image("https://www.shareicon.net/data/2016/06/18/596452_excel_512x512.png")));
// Azioni svolte dai vari bottoni
// Bottone BlackPDFLogo.png
pdfLogo.setOnMouseClicked((event) -> {
try {
if (boxes.getChildren().contains(completation))
boxes.getChildren().remove(completation);
fileChooser();
boxes.getChildren().add(filesChoosed);
} catch (Exception e) {
e.printStackTrace();
}
});
// Bottone BlackExcelLogo.png
buttonConversion.setOnMouseClicked((event) -> {
try {
conversionPDFtoEXCEL();
completation.setFont(Font.font(STYLESHEET_CASPIAN, 15));
if (boxes.getChildren().contains(filesChoosed))
boxes.getChildren().remove(filesChoosed);
boxes.getChildren().add(completation);
} catch (Exception e) {
e.printStackTrace();
}
});
// Creazione elementi aggiuntivi (scritte) della scena
Text text1 = new Text(
"Clicca il logo PDF per scegliere i file .pdf e il logo Excel per convertirli in file .xlsx.");
Text text2 = new Text("Li potrai visualizzare nella stessa cartella del file .pdf selezionato.");
text1.setFont(Font.font(STYLESHEET_CASPIAN, 15));
text2.setFont(Font.font(STYLESHEET_CASPIAN, 15));
// Creazione della box orizzontale contenente i bottoni
HBox buttonHb = new HBox(pdfLogo, buttonConversion);
buttonHb.setSpacing(30);
buttonHb.setAlignment(Pos.CENTER);
// Configurazione della box verticale che comprende tutti gli elementi della
// scena
boxes = new VBox(text1, text2, buttonHb);
boxes.setSpacing(40);
boxes.setAlignment(Pos.CENTER);
// Costruzione finale della scena
Scene scene = new Scene(boxes, 620, 360);
scene.setFill(Color.CADETBLUE);
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* Metodo per la gestione completa (creazione, setup e funzionamento) del
* FileChooser
*/
public void fileChooser() {
// Inizializzazione del FileChooser
FileChooser fileChooser = new FileChooser();
// Configurazione del FileChooser
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("PDF", "*.pdf"));
fileChooser.setTitle("Scegli i file PDF da convertire");
// Scelta dei file tramite FileChooser
file = fileChooser.showOpenMultipleDialog(primaryStage);
}
/**
* Metodo per la conversione del/dei file selezionato/i
*/
public void conversionPDFtoEXCEL() {
for (int i = 0; i < file.size(); i++) {
// Variabile di classe File per gestire singolarmente i file della lista
File convF = file.get(i);
// Variabili String che contengono nomi di filePDF, fileXLSX e dirFiles
pdfFileName = convF.getName();
excelFileName = pdfFileName.replaceFirst(".pdf", ".xlsx");
dir = convF.getAbsolutePath().replaceFirst(pdfFileName, "");
// Creazione di una variabile di classe PdfDocument che conterra' il file preso
// dalla lista
Converter pdf = new Converter(dir + pdfFileName);
// Caricamento del file .pdf
SpreadsheetConvertOptions opsConv = new SpreadsheetConvertOptions();
System.out.println("Conversione del file .pdf seguente: " + pdfFileName);
// Salvataggio del file .pdf in file .xlsx
pdf.convert(dir + excelFileName, opsConv);
pdf.close();
System.out.println("File .xlsx creato: " + excelFileName);
System.out.println("-------------");
}
System.out.println("Conversione totale completata.");
}
/**
* Metodo Main, il launch serve ad avviare l'intero programma
*/
public static void main(String[] args) {
launch(args);
}
}
And this is my pom.xml file (Maven project)
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.conversion</groupId>
<artifactId>application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar </packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>application.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>GroupDocsJavaAPI</id>
<name>GroupDocs Java API</name>
<url>http://repository.groupdocs.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-conversion</artifactId>
<version>22.3</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
</dependencies>
</project>
INSTRUCTIONS OF THE PROGRAM:
- Press PDF Logo to load PDF files
- Press Excel Logo to start the conversion ("CONVERSIONE FINITA" means that it has finished).
When I run it in cmd, using the cmdline:
java -jar application-0.0.1-SNAPSHOT.jar
it gives me those lines of errors:
Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.NoClassDefFoundError: com/groupdocs/conversion/options/convert/ConvertOptions
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$2(LauncherImpl.java:352)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.groupdocs.conversion.options.convert.ConvertOptions
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 11 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
... 5 more
I tried so many times to fix them but I really can't figure out a solution.