Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Error: Could not find or load main class

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Error: Could not find or load main class

    Dear Sir,


    i am trying execute java batch programs.

    program successfully compiled using netbeans ide.


    but i am trying to run that through command line

    this is my classpath:

    set classLogPath=D:\Apps\AttendanceBatch\CGS_Attendanc e\logs\
    set batchJarPath=D:\Apps\AttendanceBatch\CGS_Attendanc e\jarFiles\
    set classpath=%batchJarPath%mysql-connector-java-5.0.8-bin.jar;.;%batchJarPath%CGSBatch.jar;
    java -cp %classpath% com.ets.to.batch.attendance.main.ProcessAttendance Main>>%classLogPath%processAttendance.log;


    Command line through the error:

    D:\Apps\AttendanceBatch\CGS_Attendance>Processatte ndance.bat

    D:\Apps\AttendanceBatch\CGS_Attendance>set classLogPath=D:\Apps\AttendanceBatch\
    CGS_Attendance\logs\

    D:\Apps\AttendanceBatch\CGS_Attendance>set batchJarPath=D:\Apps\AttendanceBatch\
    CGS_Attendance\jarFiles\

    D:\Apps\AttendanceBatch\CGS_Attendance>set classpath=D:\Apps\AttendanceBatch\CGS
    _Attendance\jarFiles\mysql-connector-java-5.0.8-bin.jar;.;D:\Apps\AttendanceBatc
    h\CGS_Attendance\jarFiles\CGSBatch.jar;

    D:\Apps\AttendanceBatch\CGS_Attendance>java -cp D:\Apps\AttendanceBatch\CGS_Atte
    ndance\jarFiles\mysql-connector-java-5.0.8-bin.jar;.;D:\Apps\AttendanceBatch\CGS
    _Attendance\jarFiles\CGSBatch.jar; com.ets.to.batch.attendance.main.ProcessAtten
    danceMain; 1>>D:\Apps\AttendanceBatch\CGS_Attendance\logs\pro cessAttendance.log

    Error: Could not find or load main class com.ets.to.batch.attendance.main.Proces
    sAttendanceMain;
    D:\Apps\AttendanceBatch\CGS_Attendance>





    How to fix it please help.

    i have set both java classpath and path.
    my java version is jdk1.7.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Error: Could not find or load main class

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Error: Could not find or load main class

    What is a java batch file? Do you mean the java source file?

    Since it compiles and runs in Netbeans, the problem is probably with your file structure, the directory you're in when issuing the command at the command line, and the command you're using. If your source file includes a package statement, the problem is more complicated but still solvable. Hopefully, the link Mr. Workman provided will give you some clues how to fix those relatively minor problems.

    Good luck.

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Error: Could not find or load main class

    Hello.
    Try removing the last semicolon in the third and fourth statements and execute again.
    Let me know if the errors still persist.

    Syed.

    --- Update ---

    Hello.
    I just checked. I believe there is no issues with semicolons as I said earlier.
    What I suggest is all the jar files you added in the netbeans project should be provided on the system variable "CLASSPATH".
    Then create jar file for each package you have defined.
    Add all these jars as well onto the "CLASSPATH".
    Then execute "java" command and provide the fully qualified name of the main class.

    Syed.

Similar Threads

  1. Could not find or load main class
    By user2013 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 9th, 2013, 04:41 PM
  2. Error: Could not find or load main class
    By lijepdan in forum Java Theory & Questions
    Replies: 8
    Last Post: March 22nd, 2013, 04:32 PM
  3. Execution of .jar file: Could not find main class....Error'
    By suyog53 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2012, 02:04 PM
  4. Replies: 4
    Last Post: September 3rd, 2012, 02:47 AM
  5. newbie question: Error: Could not find or load main class Java Result: 1
    By ideaman in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 1st, 2012, 11:40 PM