2

I haven't run Java in ages, and was hopeful to test a small CSV reader with a simple class. The CSV reader in question is this one here http://opencsv.sourceforge.net

I've create a small class named DecryptCsv, that's really just a main method that tries to create a CSVReader.

I've got the

import com.opencsv.*;

at the top, and am able to compile my file with javac -cp "./opencsv-3.6.jar" DecryptCsv.java

If I try to run it without the jar, using java DecryptCsv it understandably crashes with:

Exception in thread "main" java.lang.NoClassDefFoundError: com/opencsv/CSVReader

If I try to set the class path when running though, I don't get what I expect. This:

java -cp ".;./opencsv-3.6.jar" DecryptCsv

Yields this:

Error: Could not find or load main class DecryptCsv

What's the proper way to run the main method in this simple class, that has this jar file requirement?

Thanks for the help!

Here's test class code:

import java.io.FileReader;
import java.io.IOException;

import com.opencsv.*;

public class DecryptCsv
{
    public DecryptCsv()
    {
        // foo
    }

    public static void main(String[] args)
    {
        try
        {
            CSVReader reader = new CSVReader( new FileReader( "file.txt" ), ',');
        }
        catch( Exception exc )
        {

        }
        System.out.println( "success" );
    }

}

The jar can be downloaded at http://sourceforge.net/projects/opencsv/

Saeven
  • 2,280
  • 1
  • 20
  • 33
  • I think your running class from command prompt? Before compiling your class set Classpath for that jar, then hit java c – KhAn SaAb Jan 07 '16 at 22:27
  • See http://stackoverflow.com/questions/34641095/jsoup-issues-could-not-find-or-load-main-class#comment57028368_34641095 –  Jan 07 '16 at 22:28
  • Thanks for the help guys. This here, has the same problem: `java -cp "opencsv-3.6.jar;." DecryptCsv` which seems to be the conclusion in that question? "Could not find or load main class DecryptCsv" – Saeven Jan 07 '16 at 22:47
  • Am on OS X if that makes any difference, using Java 8 – Saeven Jan 07 '16 at 22:47
  • 1
    That does make a difference, see http://stackoverflow.com/questions/4528438/classpath-does-not-work-under-linux – nos Jan 07 '16 at 23:24
  • That was it nos. Damn. Answer it up I'll dish marks – Saeven Jan 07 '16 at 23:25

0 Answers0