1

I tried to compile a java file using CMD but I got error of these. I have follow other solutions on stackoverflow but still not solved.

C:\Users\User\eclipse-workspace\Calendar_v1\src\cal>javac ShiftSetting.java

ShiftSetting.java:7: error: package org.apache.poi.ss.usermodel does not exist
import org.apache.poi.ss.usermodel.Cell;
                                  ^
ShiftSetting.java:8: error: package org.apache.poi.ss.usermodel does not exist
import org.apache.poi.ss.usermodel.DataFormatter;
                                  ^
ShiftSetting.java:9: error: package org.apache.poi.ss.usermodel does not exist
import org.apache.poi.ss.usermodel.Row;
                                  ^
ShiftSetting.java:10: error: package org.apache.poi.xssf.usermodel does not exist
import org.apache.poi.xssf.usermodel.XSSFSheet;
                                    ^
ShiftSetting.java:11: error: package org.apache.poi.xssf.usermodel does not exist
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
                                    ^
ShiftSetting.java:21: error: cannot find symbol
                        XSSFWorkbook wb = new XSSFWorkbook(file);
                        ^
  symbol:   class XSSFWorkbook
  location: class ShiftSetting
ShiftSetting.java:21: error: cannot find symbol
                        XSSFWorkbook wb = new XSSFWorkbook(file);
                                              ^
  symbol:   class XSSFWorkbook
  location: class ShiftSetting
ShiftSetting.java:22: error: cannot find symbol
                        XSSFSheet sheet = wb.getSheetAt(0);
                        ^
  symbol:   class XSSFSheet
  location: class ShiftSetting
ShiftSetting.java:24: error: cannot find symbol
                        DataFormatter formatter = new DataFormatter();
                        ^
  symbol:   class DataFormatter
  location: class ShiftSetting
ShiftSetting.java:24: error: cannot find symbol
                        DataFormatter formatter = new DataFormatter();
                                                      ^
  symbol:   class DataFormatter
  location: class ShiftSetting
ShiftSetting.java:29: error: cannot find symbol
                                Row r = sheet.getRow(rowNum);
                                ^
  symbol:   class Row
  location: class ShiftSetting
ShiftSetting.java:32: error: cannot find symbol
                                        Cell cell = r.getCell(m);
                                        ^
  symbol:   class Cell
  location: class ShiftSetting
ShiftSetting.java:39: error: cannot find symbol
                                Row r = sheet.getRow(rowNum);
                                ^
  symbol:   class Row
  location: class ShiftSetting
ShiftSetting.java:43: error: cannot find symbol
                                        Cell cell = r.getCell(m);
                                        ^
  symbol:   class Cell
  location: class ShiftSetting
14 errors

here is the ShiftSetting.java file that I'm trying to compile

 package cal;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ShiftSetting {
    public static void main(String[] args) {
    // code
    }
}

I have import all the APACHE-POI jar files into my java build path

enter image description here

I have added those path to user environment variable too like this

enter image description here

Can anyone tell me which way should I try now? because I don't have any idea what to do anymore.

sharky
  • 196
  • 1
  • 1
  • 14
  • 1
    If you are using Eclipse, then why are you bothering with compiling and/or running directly from the command line? If your Eclipse classpath be correct, which it looks, then it should work from Eclipse. – Tim Biegeleisen Dec 17 '18 at 06:05
  • I need to implement my project to other computer as well? @TimBiegeleisen – sharky Dec 17 '18 at 06:06
  • I have no idea what that comment is supposed to mean. – Tim Biegeleisen Dec 17 '18 at 06:06
  • @TimBiegeleisen I need to implement the current project that I am developing to other computer. Hence, I guess the best way is to run the java project is by run it on CMD. – sharky Dec 17 '18 at 06:08
  • can you explain more on the "classpath is missing that JAR"? – sharky Dec 17 '18 at 06:15
  • Include your the current `javac` you are running. My guess is that the classpath is missing that JAR. – Tim Biegeleisen Dec 17 '18 at 06:19
  • @TimBiegeleisen you mean when I execute the command on the CMD, i need to include classpath also? can you give me example? – sharky Dec 17 '18 at 08:38
  • 1
    What does “to implement my project to other computer” mean? There is no need to recompile Java programs to run them on a different computer. Just copy the compiled program. Eclipse offers export options for that. – Holger Dec 17 '18 at 10:25
  • I want my program to run on other computer without having through Eclipse. Just run it through CMD. @Holger – sharky Dec 17 '18 at 23:29
  • As said, after compiling (which your Eclipse already does), the classes *are* executable in any environment with a JVM. There is no need to compile them again. You only have to transfer the classes. As also said, Eclipse offers options to do that, e.g. to package the classes into a jar file, within the “Export” menu item. Sometimes, it really helps to read the documentation. That also applies to `javac`, if you insist on using it. – Holger Dec 18 '18 at 09:52

1 Answers1

3

My problem was the classpath. After several attempts of trying I now can compile all the 8 jar files in a single line like this:

C:\Users\User\eclipse-workspace\Calendar_v1\src\cal>javac -cp jars/dom4j-1.6.1.jar;jars/poi-3.2-final.jar;jars/poi-3.7.jar;jars/poi-examples-3.7.jar;jars/poi-ooxml-3.7.jar;jars/poi-ooxml-schemas-3.7.jar;jars/poi-scratchpad-3.7.jar;jars/xmlbeans-2.3.0.jar ShiftSetting.java

Problem solved ( btw this is for window )

sharky
  • 196
  • 1
  • 1
  • 14