0

Here is my pomfile.xml:

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"> 4.0.0 com.rasweeny Recipes 1.0-SNAPSHOT jar
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
    <exec.mainClass>com.rasweeny.recipes.Recipes</exec.mainClass>
</properties>

<dependencies>

    <dependency>
        <groupId>com.github.pcorless.icepdf</groupId>
        <artifactId>icepdf-core</artifactId>
        <version>7.0.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>com.github.pcorless.icepdf</groupId>
        <artifactId>icepdf-viewer</artifactId>
        <version>7.0.1</version>
        <type>jar</type>
    </dependency>
</dependencies>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <configLocation>config/sun_checks.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</reporting>

<build>  

    <plugins>  
        <plugin>  
            <!-- Build an executable JAR -->  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-jar-plugin</artifactId>  
            <version>3.1.0</version>  
            <configuration>  
                <archive>  
                    <manifest>  
                        <mainClass>com.rasweeny.recipes.Launcher</mainClass>  
                    </manifest>  
                </archive>  
            </configuration>  
        </plugin>  
    </plugins>  
    
    <resources>
        <resource>
            <directory>[Users/rasweeny/jarfiles/icepdf-7.0.1/]</directory>
            <includes>
                <include>[icepdf-core-7.0.1.jar]</include>
                <include>[icepdf-viewer-7.0.1.jar]</include>
                <include>[fontbox-2.0.27.jar]</include>

                <include>[resource file #n]</include>
            </includes>
        </resource>

    </resources>
</build>  
 </project>

The imports :

import org.icepdf.ri.common.ComponentKeyBinding; import org.icepdf.ri.common.SwingController; import org.icepdf.ri.common.SwingViewBuilder;

Here is my code :

 if (exten.equals("pdf")) {
  String filePath = file;
  SwingController controller = new SwingController();
  SwingViewBuilder factory = new SwingViewBuilder(controller);
  SPanel viewerComponentPanel = (SPanel) factory.buildViewerPanel();
  ComponentKeyBinding.install(controller, viewerComponentPanel);

  controller.getDocumentViewController().setAnnotationCallback(
          new org.icepdf.ri.common.MyAnnotationCallback(
                  controller.getDocumentViewController()));

  // Create a JFrame to display the panel in
  JFrame window = new JFrame(fileName);
  Dimension pdfSize = new Dimension(640,800);
  window.setMinimumSize(pdfSize);
  window.setMaximumSize(pdfSize);
  window.setPreferredSize(pdfSize);
  window.add(viewerComponentPanel);
  window.pack();
  window.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width)

/ 2 - 600 / 2, (Toolkit.getDefaultToolkit().getScreenSize().height) / 2 - 800 / 2); window.setVisible(true);

 controller.openDocument(filePath);

If I run it in netbeans everything works fine. Once I clean and build it and move the application to a folder on my drive. I get this error.

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/icepdf/ri/common/views/Controller at com.rasweeny.recipes.Recipes.lambda$setupGUI$0(Recipes.java:142) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) .....

Line 142 is : window.pack(); I have added icepdf as a dependency to the app in the local repository.

I am using Mac OSX 10.15.7 Catalina, JDK 17, Netbeans 16, and Maven 4.0.0.

What am I missing? Thanks, Rich

Sorry here is the full output:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/icepdf/ri/common/views/Controller at com.rasweeny.recipes.Recipes.lambda$setupGUI$0(Recipes.java:142) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715) at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90) Caused by: java.lang.ClassNotFoundException: org.icepdf.ri.common.views.Controller at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 14 more rasweeny:recipes rasweeny$

Like I said it works fine launching from Netbeans but I get this error when trying to launch it from my hardd rive.

rasweeny
  • 11
  • 3
  • "_Once I clean and build it and move the application to a folder on my drive, I get this error_" - Does that JAR file contain the dependent classes for ICE PDF (a "fat" JAR)? If not then you have to ensure those dependent JARs are on the classpath when you run your app - otherwise you will get this `NoClassDefFoundError` problem. Just running `java -cp YourApp.jar com.rasweeny.recipes.Recipes` is not sufficient. – andrewJames Mar 11 '23 at 20:25
  • As mentioned above you'll need the core, viewer and font jars on your classpath. Might also recommend the encryption and the image handling jars for a better experience with the library. – pcorless Mar 13 '23 at 02:58
  • I have added the full output. – rasweeny Mar 13 '23 at 11:26
  • I am opening a pdf to view and print. I am not editing anything. – rasweeny Mar 13 '23 at 11:28
  • What do you mean by "_launch it from my hard drive_"? Can you clarify? – andrewJames Mar 13 '23 at 12:37
  • In the terminal : java -jar Recipes-1.0-SNAPSHOT.jar – rasweeny Mar 13 '23 at 15:49
  • That brings us back to my first comment. You have to tell Java where those other JARs are, by placing them on the Java classpath (assuming the Recipes JAR is not a "fat" JAR). One way: create a new `lib` directory in the same location where the Recipes JAR is. Add the other JAR files into that directory and then tell Java about it: `java -cp Recipes-1.0-SNAPSHOT.jar:lib/* com.rasweeny.recipes.Recipes`. – andrewJames Mar 13 '23 at 15:58
  • Or, run the application [using Maven](https://stackoverflow.com/q/15869784/12567365). – andrewJames Mar 13 '23 at 15:58
  • Thank you James. It is the first time using Maven. I usually use Ant. I didn't realize it is so involved. Looks like I have some reading to do. – rasweeny Mar 13 '23 at 19:35

0 Answers0