"Cannot find main" error when attempting to run "java name.class" file

I'm not a Java programmer, but my boss tasked me with getting someone else's code running. Sorry for the noob question.

I have the code running perfectly via `Eclipse` on my OSX system. However, the need is for it to be running from the command line.

I'm trying to run the code on my OSX box that was compiled by eclipse when I ran it there.

I've set up the environment as best I can. But when I attempt to run the *.class files, I get...

    init mikes$ pwd
    /Users/(snip)/Eclipseworkspace/Anonymize/bin/init

    init mikes$ java Init.class
    Error: Could not find or load main class Init.class

    init mikes$ java ./Init.class
    Error: Could not find or load main class ..Init.class

`main` is definitely in Init.class

**Init.java**

    package init;
   
    import java.io.File;
    import java.io.IOException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.util.stream.Stream;
    import java.net.*;
   
    import anonymizer.Anonymizer;
   
    public class Init  {
          
          public static String STOPWORDS;
          (...snip...)

          static {
                // Define location of resource files
                 STOPWORDS = "misc" + File.separator + "stopwordlist_de.txt";
            (...snip...)
          }
          
          public static void main(String[] args) throws IOException {            
                if (args.length !=1) {
                      System.err.println("Usage: Anonymize <path to docx files>");
                      System.exit(1);
                    }
                try (Stream<Path> paths = Files.walk(Paths.get(args[0]))) {
                      paths.skip(1).filter(file -> file.toString().endsWith("docx")).forEach(file -> {
                                  Anonymizer ano;
                            try {
                                  // Creates an instance of the Anonymizer class and executes the pipeline
                                  ano = new Anonymizer(file.toString(), file.toString()+".anon");
                                    ano.anonymizeAdmissionNotes();
                            } catch (Exception e) {
                                  e.printStackTrace();
                            }
                      });
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                
                System.out.println("De-Identification finished.");
   
          }
    }    

** Directory Structure **

    Anonymize mikes$ pwd
    /Users/(snip)/Eclipseworkspace/Anonymize/
   
    Anonymize mikes$ find . | grep -v <non_pertinent_stuff>
    .
    ./misc
    ./misc/suffixes_towns.txt
    ./misc/regex_mappings_surnames.txt
    ./misc/regex_mappings_international_firstnames.txt
    ./misc/suffixes_streets.txt
    ./misc/tokenizer.jar
    ./misc/stopwordlist_de.txt
    ./misc/regex_mappings_streets_with_numbers_and_abr.txt
    ./misc/header_tokens.txt
    ./misc/regex_mappings_general.txt
    ./misc/regex_mappings_towns_and_villages.txt

    ./bin
    ./bin/init
    ./bin/init/Init.class
    ./bin/anonymizer
    ./bin/anonymizer/DocxReader.class
    ./bin/anonymizer/Anonymizer.class
    ./bin/anonymizer/NamedEntityRecognizer.class
    ./.classpath

    ./lib
    ./lib/xmlbeans-2.6.0.jar
    ./lib/poi-3.17.jar
    ./lib/poi-ooxml-schemas-3.17.jar
    ./lib/poi-ooxml-3.17.jar
    ./lib/stanford-german-corenlp-2017-06-09-models.jar
    ./lib/stanford-corenlp-3.8.0.jar

** This is how I tried to setup the environment, and run the code. **

    init mikes$ export CLASSPATH="${CLASSPATH}:.:\
    /Users/(snip)/Eclipseworkspace/Anonymize/bin/:\
    /Users/(snip)/Eclipseworkspace/Anonymize/bin/init/:\
    /Users/(snip)/Eclipseworkspace/Anonymize/bin/anonymizer/:\
    /Users/(snip)/Eclipseworkspace/Anonymize/lib/:\
    /Users/(snip)/Eclipseworkspace/Anonymize/misc/"

    init mikes$ export PATH="${PATH}:${CLASSPATH}"

    init mikes$ pwd
    /Users/(snip)/Eclipseworkspace/Anonymize/bin/init

    init mikes$ java Init.class
    Error: Could not find or load main class Init.class

    init mikes$ java ./Init.class
    Error: Could not find or load main class ..Init.class

    init mikes$ java init.Init
    Error: Could not find or load main class java

**I'm not finding my mistake. What do I need to change/do, to get this code running from the command line?**


  [1]: https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean
LVL 3
Mike R.Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Try
java -cp /Users/(snip)/Eclipseworkspace/Anonymize/bin init.Init

Open in new window


When they're done in the IDE, Java apps should be in executable jars (hint: 'export' in Eclipse)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike R.Author Commented:
OK. That was it :) I tried a half doze variations of that I found on the web, but I was missing the `package` prefix. Thank you. I'll look for a link on how to export.
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.