3

I am a beginner in java. I have downloaded a latest version of apache poi 3.16.
There are several jar files renamed and edited from old versions. i want to know how to set class path for the files in steps and what are all the jar files that need class path? I have imported all the jar files but it showed class not found exception in this code.

import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class CreateWorkBook 
{
   public static void main(String[] args)throws Exception 
   {
      //Create Blank workbook
      XSSFWorkbook workbook = new XSSFWorkbook(); 
      //Create file system using specific name
      FileOutputStream out = new FileOutputStream(
      new File("createworkbook.xlsx"));
      //write operation workbook using file out object 
      workbook.write(out);
      out.close();
      System.out.println("
      createworkbook.xlsx written successfully");
   }
}

2 Answers2

1

Before setting the classpath for the jars create a lib folder with in your project folder and copy all the jar files in this folder. For example:

D:\Project\Java\lib

After that include this location in your path.

For setting the path and classpath you can check this link:

https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

For setting the path following steps:

Go to system properties

Click on advanced system settings

Click on environment variables

vin
  • 231
  • 1
  • 17
  • I would not recommend adding third party libraries in Java lib directory as it might cause conflicts in future with other projects. Application level dependencies should be dealt at the application level and not at the system level. – Pavan Kumar Jan 10 '17 at 12:26
  • Agreed with you but he is beginner so I have given simplest way to set the path. – vin Jan 10 '17 at 12:36
1

If using Eclipse, follow https://stackoverflow.com/a/3280384/3940047 for instructions. This library has other dependencies that need to be imported - ensure you've done that.

com.github.virtuald » curvesapi

org.apache.poi » poi

org.apache.poi » poi-ooxml-schemas

If using Maven, modify the pom.xml to include the poi-ooxml library. Transitive dependencies are taken care of by Maven.

Please share exact exception trace and your environment details to help you further. I would not recommend to add the third party libraries to Java lib directory as it might add conflicts in future with other projects.

Community
  • 1
  • 1
Pavan Kumar
  • 4,182
  • 1
  • 30
  • 45