1 Reply Latest reply: Feb 24, 2010 10:43 PM by EJP RSS

    Project doesn't seem to work from command line

    843810
      hi all

      i wrote a small java program which uses some jar files(written by me) .i used eclipse IDE and set the buildpath to the jars and it runs perfect in the IDE but when i try to execute it from the command line
      it gives me class not found exception.i am using packages in my structure
      like com.company.test.java
      it compiles fine from the command line but doesn't run.Here is my directory struture

      root
      |_bin
      |_lib(contains the jar files i created)
      |_src
      |_com
      |_company
      |_test.java

      my goal is to generate class file and redirect it to bin dir and then run it from command line

      here are the statements i use
      javac -classpath lib/test1.jar;lib/test2.jar src/com/company/test.java(this generates .class file)
      java -classpath lib/test.jar;lib/test2.jar src/com/company/test

      and this gives
      exception in thread main:no class def found error..

      could someone guide me through.I need to do this using a batch script and hence my struggle for command line method.

      thanks
      Sree
        • 1. Re: Project doesn't seem to work from command line
          EJP
          java -classpath lib/test.jar;lib/test2.jar src/com/company/test
          Assuming the classpath is correct there are several things wrong with that.

          1. The class argument to 'java' is a classname. That's a filename. Classnames have package qualifiers separated bt dots. Filenames have directories separated by slashes.

          2. Classnames by convention start with a capital letter, so 'test' should surely be 'Test', unless your code code says 'public class test'.

          3. Unless your class is in a package called 'src.com.company' it is wrong anyway. I suspect it should be 'com.company.Test' but without seeing your source code it is impossible to know.