Search code examples
javanetbeanspackagedirectory-structure

How to use a package name independent of the directory structure?


I want a Java application to have a directory structure like the following (like maven):

src
  main
    java
      org
        example

When I add a new Java class called NewClass using the Netbeans IDE, it creates the package statement in NewClass.java as package main.java.org.example;.

If I remove main.java. from the package statement I get the error Incorrect package.

I do not want main.java. in the package statement, but I do want my directory hierarchy as mentioned above.

How do I get the package naming and the directory structure to play along?


Solution

  • You need to change your source directory from /src to /src/main/java