1

When I try to run this benchmark java8-lambda-benchmark.

Using the comand:

java -cp build/jar/LambdaMicrobench.jar lambdademo.LambdaAvgExtraParallel 50000

I get the following error:

lambdademo/load_employees.csv: Not found in jar
java.lang.NullPointerException
at lambdademo.EmployeeFile.loadEmployeeList(Unknown Source)
at lambdademo.LambdaAvgExtraParallel.main(Unknown Source)
Exception in thread "main" java.lang.NullPointerException
at lambdademo.EmployeeFile.loadEmployeeList(Unknown Source)
at lambdademo.LambdaAvgExtraParallel.main(Unknown Source

The file EmployeFile.java is the following:

public class EmployeeFile {

private static final String EMPLOYEE_FILE = "lambdademo/load_employees.csv";

public LinkedList<EmployeeRec> loadEmployeeList() {
    LinkedList<EmployeeRec> employeeList = new LinkedList<>();
    BufferedReader br = null;
    try {
         URL fileURL = getClass().getClassLoader().getResource(EMPLOYEE_FILE);
          if (fileURL == null) {
                   System.out.println("resource is null");
             }
          InputStream in = fileURL.openStream();
          br = new BufferedReader(new InputStreamReader(in));             
               } catch (Exception e) {
        System.out.println(EMPLOYEE_FILE + ": Not found in jar");
        e.printStackTrace();
    }

    try {
        String line;
        while ((line = br.readLine()) != null) {    
            String[] rec = null;
            rec = line.split(",");
            employeeList.add(new EmployeeRec(rec[0], rec[1], rec[2],
                    rec[3], rec[4], rec[5]));
        }
    } catch (IOException e) {
        System.out.println("Error reading " + EMPLOYEE_FILE);
        e.printStackTrace();
    }
    return employeeList;
}

Now I print the value of fileURL I get null. The csv file is within the same folder as the sources for the project.

2
  • 1
    How do you create the LambdaMicrobench.jar (e.g. using an IDE, maven, ant, ... )? Can you confirm that the .csv is at the right location inside the .jar (a .jar is a .zip file, just use 7zip/unzip/tar or a similar tool to unpack its content)? Commented May 29, 2015 at 6:04
  • I built with ant : ant -buildfile build.xml Commented May 29, 2015 at 6:18

2 Answers 2

2

when I use jar -xvf build/jar/LambdaMicrobench.jar I get this output

 created: META-INF/
inflated: META-INF/MANIFEST.MF
 created: lambdademo/
inflated: lambdademo/Constants.class
inflated: lambdademo/EmployeeFile.class
inflated: lambdademo/EmployeeRec.class
inflated: lambdademo/LambdaAvgExtraParallel.class
inflated: lambdademo/LambdaAvgExtraSerial.class
inflated: lambdademo/LambdaAvgParallel.class
inflated: lambdademo/LambdaAvgSerial.class
inflated: lambdademo/OldSchoolAvg.class
inflated: lambdademo/OldSchoolAvgExtra.class
inflated: load_employees.csv

These are correct as the project file structure is:

--LambdaMicrobench
----load_employees.csv
----lambdademo
------*.class

The solution is to change that field,load_employees.csv instead of lambdademo/load_employees.csv

private static final String EMPLOYEE_FILE = "load_employees.csv"; 
Sign up to request clarification or add additional context in comments.

1 Comment

IF the csv is at the root of the jar, then the path should be String EMPLOYEE_FILE = "load_employees.csv"; why do you reference the folder if it isn't in it?
1

The getResource() method works with the classpath. In your example classpath, you have only the jar, so whatever is outside of the jar can't be found.

You can either open up the jar with the zip tool of your choice and put the .csv file in, or an easier solution add the directory where the csv file is into the classpath with java -cp <directory>:build/jar/LambdaMicrobench.jar lambdademo.LambdaAvgExtraParallel 50000.

Note that the : separator needs to be ; if you're on windows.

2 Comments

the csv file in in this folder src/lambdademo but using this command I still get the same error as beforejava -cp src/lambdademo:build/jar/LambdaMicrobench.jar lambdademo.LambdaAvgExtraParallel 50000
Just use src, the lambdademo part seems to be defined already in EMPLOYEE_FILE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.