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 9161599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:00:12+00:00 2026-06-17T14:00:12+00:00

I need to compile an external java file (say a.java). This is the code

  • 0

I need to compile an external java file (say a.java). This is the code i wrote for the same.

(String path contains the path to the java and class file)

    command[0] = "javac";
    command[1] = path+"a.java";
    p = Runtime.getRuntime().exec(command);        

The above code seems to work just fine. But the below code

    command[0] = "java";
    command[1] = "a";
    command[2] = "-cp";
    command[3] = "."+path+"a";
    p = Runtime.getRuntime().exec(command);        
    stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    while ((temp = stdInput.readLine()) != null) result += "\n" + temp;
    while ((temp = stdError.readLine()) != null) result += "\n" + temp;

Causes the following error

java.lang.NoClassDefFoundError: a
Exception in thread "main" 

Could someone explaine the problem with this code. Thanks !

  • 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-17T14:00:14+00:00Added an answer on June 17, 2026 at 2:00 pm

    You’re specifying the class name first, and then the arguments for the classpath. The class name is always the last thing to come before the program-specific arguments. In your case, the classpath part will therefore not be treated as an option – it’ll be considered as two arguments (-cp and the path) to the Java program itself.

    So instead of:

    java a -cp (whatever)
    

    you want

    java -cp (whatever) a
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to compile some files in my solution with an external command line
I need to compile this project: https://github.com/boatmeme/microsoft-translator-java-api i create a project named microsoft-translator-java-api in
I need to compile the unit with /EHsc option, how could i set this
I need to compile my GWT 1.7 project from my ant build file....anyone know
I need to compile some mfc code that was written using Visual C++ 6.0
I have a single .java (driver.java) file I'm trying to compile and run from
I try to compile this code: static uint64_t push(int fd, SOCKET sock, SSL *ssl,
I'm trying to compile the following snippet of code: #include <boost/filesystem/path.hpp> //Other includes snipped
I need to build a jar file that includes (other, external projects') Maven artefacts.
I'm fairly new to Java and need to add an external Jar to the

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.