Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:24:35+00:00 2026-06-09T13:24:35+00:00

How exactly do I run a .java TestNG project from a command line? I

  • 0

How exactly do I run a .java TestNG project from a command line?

I have read through the TestNG documentation, and tried the following to no avail:

C:\projectfred> java org.testng.TestNG testng.xml 

… with the following testng.xml file in my project:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >  
<suite name="SuiteAll" verbose="1">
    <test name="TestAll">  
        <packages>  
            <package name="com.project.fred.tests"/>
        </packages>  
    </test>  
</suite>

The error I get is this:

Exception in thread "main" java.lang.NoClassDefFoundError: org/testng/TestNG
Caused by: java.lang.ClassNotFoundException: org.testng.TestNG
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.testng.TestNG.  Program will exit.

Obviously, I am not referencing TestNG correctly in my command line. Does anyone know how to get this working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:24:36+00:00Added an answer on June 9, 2026 at 1:24 pm

    You need to have the testng.jar under classpath.

    try C:\projectfred> java -cp "path-tojar/testng.jar:path_to_yourtest_classes" org.testng.TestNG testng.xml

    Update:

    Under linux I ran this command and it would be some thing similar on Windows either

    test/bin# java -cp ".:../lib/*" org.testng.TestNG testng.xml
    

    Directory structure:

    /bin - All my test packages are under bin including testng.xml
    /src - All source files are under src
    /lib - All libraries required for the execution of tests are under this.
    

    Once I compile all sources they go under bin directory. So, in the classpath I need to specify contents of bin directory and all the libraries like testng.xml, loggers etc over here. Also copy testng.xml to bin folder if you dont want to specify the full path where the testng.xml is available.

     /bin
        -- testng.xml
        -- testclasses
        -- Properties files if any.
     /lib
        -- testng.jar
        -- log4j.jar
    

    Update:

    Go to the folder MyProject and type run the java command like the way shown below:-

    java -cp ".: C:\Program Files\jbdevstudio4\studio\plugins\*" org.testng.TestNG testng.xml
    

    I believe the testng.xml file is under C:\Users\me\workspace\MyProject if not please give the full path for testng.xml file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run the following command from command line, I can run 7-zip as
Questions exactly like this have been asked before, i've read them all and tried
I have run the following code in this page RsyntaxTextArea using Java and i
I have a java project written using eclipse ide and I want to run
I'm new with running Java from the command line in Windows and can't get
I have followed this tutorial here as mentioned exactly I now try to run
I expose my context : I have two Java programs that run on a
I have a project that uses a Java library converted using IKVM . I
I have a little question: we have to run Java programs and parts of
I have a Java applet which doesn't need any special privileges to run (i.e,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.