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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:38:20+00:00 2026-06-06T15:38:20+00:00

I have three source files in a folder. I simply want to compile them

  • 0

I have three source files in a folder. I simply want to compile them using commandline and then execute them. However, I’m having the following issue. I am on a windows box:

Code compiles fine:

C:\mycode\src\code>javac Source1.java Source2.java Source3.java

Does not run from the folder where class files are:

C:\mycode\src\deckofcards>java Source1
Exception in thread "main" java.lang.NoClassDefFoundError: Source1 (wrong name: code/Source1)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        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: Source1.  Program will exit.

However, it does run when moving to parent folder:

C:\mycode\src\code>cd ..

C:\mycode\src>java code/Source1
Hello1
Hello2
Hello3...
......
....

I want to distribute this source to someone and I’m not sure whether they will be on windows or unix box.

Eventually I want to create an executable jar file but that also was giving me an error like this.

  • 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-06T15:38:22+00:00Added an answer on June 6, 2026 at 3:38 pm

    Problem here is not with running Java files, it runs fine. So you wanted to understand the following:

    In order to run a Java program you need to do the following steps:

    1. Create Java source files (*.java files)
    2. Compile using javac to binary class files (*.class files)
    3. Run the class files using java executable

    We use package structure to keep organize the java files. In your case it is a simple application (and you use the package named “code”), but in a large production application we need to organize our code into many packages.

    While running the class file, we need to give the class file path (which includes the package path). So in your case you need to execute java code/Source1 to run your class.

    You can learn more from this link: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html

    For creating a JAR file you can refer the link: http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

    For making a JAR file executable ensure you add manifest file with main-class attribute.

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

Sidebar

Related Questions

I have a Util package with source files in three seperate directories, defined like
I have a folder with many source code files. I would like to find
I am running Cygwin Python version 2.5.2. I have a three-line source file, called
In my source tree have Java code which is automatically generated from XSD files.
Have there been incompatibilities between Java releases where Java source code/Java class files targeting
Need some help with a query.. I have three tables. Source id name 1
i have been sent a directory tree of source code that i want to
I have a bunch of source control folders for which I want to get
I have java source code in a text file. There has to be entered
I have source XMLfiles that come in with multiple root elements and there is

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.