0

As the title says, I'm trying to run a class in Command Prompt which uses the Apache POI library but when I run this command:

java -cp C:\Users\rperera\IdeaProjects\LinkingNames\libs; HyperlinkWriter

I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/CreationHelper
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.CreationHelper
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    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)
    ... 6 more   

the libs folder contains the entire POI folder that's zipped up when downloaded so I'm not sure why it's throwing this error. I also tested this with IntelliJ and it ran fine. I know that the way Command Prompt and IntelliJ handles libraries is different but I'm not sure why this is happening.

I would appreciate any help! Thanks!

silverAndroid
  • 960
  • 3
  • 11
  • 29

2 Answers2

1

You need to actually compile the jar with the original .java files and the specified POI jars.

javac -cp \path_to_jars \path_to_java_files

and then

java MyProject
andrewdleach
  • 2,458
  • 2
  • 17
  • 25
1

I found the answer from a previous answer of StackOverflow. I had to add a '*' to the end, and a '.' after the semicolon. So with my example, in terms of compiling, I had to do:

javac -cp C:\Users\rperera\IdeaProjects\LinkingNames\libs\*;. C:\Users\rperera\IdeaProjects\LinkingNames\src\HyperlinkWriter.java

and then to run it (Credit to @andrewdleach), I just did:

java HyperlinkWriter
Community
  • 1
  • 1
silverAndroid
  • 960
  • 3
  • 11
  • 29