-1

Here is the thing: I am trying to run the example program in the joda-time project. The start of the Examples.java file looks like this:

package org.joda.example.time;

import java.util.Locale;

import org.joda.time.DateTime;
import org.joda.time.Instant;

/**
 * Example code demonstrating how to use Joda-Time.
 *
 * @author Stephen Colebourne
 */
public class Examples {

public static void main(String[] args) throws Exception {
    try {
        new Examples().run();
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}

And all the classes for compiling this Example.java is in a joda-time-2.3.jar. I can successfully compile this program by using

    javac -cp somewhere/joda-time-2.3.jar Example.java

And it generate an Example.class, but I jut cannot execute that. So far I have tried:

java Examples
java -cp somewhere/joda-time-2.3.jar Examples
java -cp somewhere/joda-time-2.3.jar org.joda.example.time.Examples

But they all generate this kind of errors:

Error: Could not find or load main class org.joda.example.time.Example

Error: Could not find or load main class Examples

And I've tried both in the org/joda/example/time folder and the parent folder of org

Anyone can give an instruction on how to execute that? Really appreciate it!

user2403909
  • 85
  • 3
  • 12
  • Possible duplicate: http://stackoverflow.com/questions/9879679/running-java-program-from-command-line?rq=1 – Ephraim Jun 12 '14 at 06:16

2 Answers2

3

Error: Could not find or load main class org.joda.example.time.Example

public class Examples {

Name of your class is Examples not Example

EDIT

Sorry for late reply...

To execute specific Java program you need to bring control to root directory so if your class is in abc/newdir/Examples.java you need to use cd command (in windows) to lead control to root directory and than compile or you can defeneitly go for the suggestion of kogut.

C:/abc/newdir>java -cp somewhere/joda-time-2.3.jar Examples
akash
  • 22,664
  • 11
  • 59
  • 87
2

Modify your classpath parameter, so it should include directory where Example.class was generated.

In case of out/org/joda/example/time/Example.class you need to use

java -cp somewhere/jodata-time-2.3.jar:out org.joda.example.time.Example
kokosing
  • 5,251
  • 5
  • 37
  • 50