Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Commons lang problems

807603Feb 10 2008 — edited Feb 10 2008
Hi there!

Sorry if I post this in the wrong section. But I was unsure of which to choose so I took the most general.

To my problem. I want to use commons lang (http://commons.apache.org/lang/) but I cant make it work. I made a simple testclass to show you the problem:
import org.apache.commons.lang.builder.ToStringBuilder;

public class Person
{
  private String name;
  private int age;

  public Person(String name, int age)
  {
    this.name = name;
    this.age = age;
  }

  public String getName()
  {
    return name;
  }

  public void setName(String newName)
  {
    this.name = newName;
  }

  public int getAge()
  {
    return age;
  }

  public void setAge(int newAge)
  {
    this.age = newAge;
  }

  public String toString()
  {
    return new ToStringBuilder(this)
      .append("name", name)
      .append("age", age)
      .toString();
  }

  public static void main(String[] args)
  {
    Person p = new Person("Peter", 23);
    System.out.println(p);
  }
}
And this is the output from when I run it:
*$ javac -classpath /usr/share/java/commons-lang.jar Person.java && java Person*
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/builder/ToStringBuilder
	at Person.toString(Person.java:36)
	at java.lang.String.valueOf(String.java:2615)
	at java.io.PrintStream.print(PrintStream.java:616)
	at java.io.PrintStream.println(PrintStream.java:753)
	at Person.main(Person.java:45)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2008
Added on Feb 10 2008
4 comments
255 views