1

I have this app for XML and flatfile generation in the src folder and I have the jarFiles in Jarfiles folder.

I was trying to compile my java file and I get this error: package org.apache.poi.hssf.usermodel does not exist, I am importing this in my java file and have the jar file in the src folder. How can I fix this problem?

Update: I tried to include the jarfiles as the answer indicated with this line in cmd javac -cp "jarFiles/*" Xls_Reader.java, it seems that I am still having the same error

Shawn
  • 15
  • 5
  • 3
    Please [don't upload text as image](https://meta.stackoverflow.com/a/285557/13447). Edit your question to contain all the information in text form - consider to use the editor's formatting options. Also see [ask]. – Olaf Kock Jul 18 '22 at 16:04
  • Hi sorry this is a new account I don't think I am allowed to insert images yet – Shawn Jul 18 '22 at 16:10
  • 3
    You should _not_ insert images, but rather their text _as text_. Read the article I've linked for the reason – Olaf Kock Jul 18 '22 at 17:34

1 Answers1

1

As it seems that you are not using a build tool like Maven or Gradle, you have to make the jar part of your classpath (to get instructions on how to do that, see https://stackoverflow.com/a/49515986/16342635.

However, I would recommend getting familiar with a build tool like Maven and to manage your dependencies (your "jar files") with that.

  • I tried to include the jarfiles as the answer indicated with this line in cmd javac -cp "jarFiles/*" Xls_Reader.java, it seems that I am still having the same error – Shawn Jul 18 '22 at 18:34
  • Could you try to move the jar-file which contains the hssf usermodel to a new folder? (Path should be /jarFiles/org/apache/) – HelloWorld123 Jul 18 '22 at 18:42
  • I have just moved the jar-file to a new folder with the path jarFiles/org/apache/, should I still run this line in cmd? javac -cp "jarFiles/*" Xls_Reader.java – Shawn Jul 18 '22 at 18:50
  • Yes, still run the same line. If that does not solve the error, use 7-zip and open the jar-files in it to see if one of them really contains the class poi/hssf/usermodel – HelloWorld123 Jul 18 '22 at 18:52
  • I just ran the line and it seems to have the issue still, I will open the jarfile to check that! Thank you! hopefully that can fix the issue – Shawn Jul 18 '22 at 18:58
  • Update: I just opened it and checked that it does contain hssf/usermodel with all the classes, is it because of the command line I am putting not the right path? – Shawn Jul 18 '22 at 19:03
  • Could you try pointing the classpath directly to the jar which contains the hasf.usermodel class instead of to jarpath/*? – HelloWorld123 Jul 18 '22 at 19:12
  • I just tried: javac -cp "C:\Users\shawlai\Desktop\MSIX_apps\MSIXfileGenerate\jarFiles\org\apache\poi\hssf\usermodel" Xls_Reader.java which is where I have the hssf\usermodel saved in, it is still giving the same error, is this command line put in properly? – Shawn Jul 18 '22 at 19:45
  • No, in this case I meant you should try this: javac -cp "/path/to/jar/jarName.jar Xls_Reader.java". So set the classpath to the path where the jar is located at which contains the class that can't be found. Sorry for being unclear – HelloWorld123 Jul 18 '22 at 20:02
  • 1
    Got it compiled now! Thank you so much! – Shawn Jul 18 '22 at 20:36
  • No problem! However, if you're planning to do more Java projects in the future, I still recommend you to get familiar with a Build Tool (the most popular one is Maven I think) as that will not only save you the trouble of having to put all libraries into the classpath, but also because adding the libraries manually can be a lot of work sometimes, e.g. if a library depends on other libraries (that's called "transitive dependency"). So if you have time to learn maven (which doesn't take very long to get started with) I would definitely recommend to do it – HelloWorld123 Jul 18 '22 at 21:35