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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:56:36+00:00 2026-05-26T00:56:36+00:00

I’m writing a project in netbeans, but I need it to be compiled with

  • 0

I’m writing a project in netbeans, but I need it to be compiled with javac, because it is needed to be built and executed through CLI. How can I do that? I’ve seen a lot of project specific answers, but none suits my problem. I’ve read javac’s man, and setted the classpath properly: javac -cp .. MyMain.java, conssidering that my project have the following structure:

src
 |_mainPackage
           |_package2
           |_package3
           |_MyMain.java

and I’m using the dot format in my imports like this:

import package1.class1
import package2.class2

public class MyMain {

  public static void main(String[] args) {
    //Stuff with classes in package1
            .
            .
            .
    //Stuff with classes in package2
            .
            .
            .
  }
}

I can’t use ant, because it is meant to be compiled using javac in the CLI, since it is a college project and have some restrictions imposed by the professors.

EDIT:
I actually got to compile my sources using javac with the command usr@host: mainPackage $ javac -cp .. MyMain.java, since my imports use dot separation format, and the “root package” is located in ‘mainPackage’ folder; but when i’m going to run the project, i have this output:

usr@host: mainPackage $ java VideoRent 
Exception in thread "main" java.lang.NoClassDefFoundError: MyMain (wrong name: mymain/MyMain)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: MyMain.  Program will exit.
  • 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-05-26T00:56:36+00:00Added an answer on May 26, 2026 at 12:56 am

    In a clean temporary directory, try this sequence of commands. Then inspect and understand the directory layout, package declarations, and various path settings like -d bin, -s src, and -cp bin:

    mkdir -p src/mainPackage
    echo "package mainPackage; public class MyMain { public static void main(String[] args) { System.out.println(\"Hello world\"); }}" > src/mainPackage/MyMain.java
    mkdir bin
    javac -d bin -s src src/mainPackage/MyMain.java 
    java -cp bin mainPackage.MyMain
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.