I would recommend to stick with default Maven layout ( and also use maven as build tool )
Productive classes / resources:
src/main/java
src/main/resources
Test data and classes:
src/test/java
src/test/resources
Maven can also take care to package your application properly with all the necessary jars ( look for maven assembly plugin )
Answer from Konstantin Pribluda on Stack OverflowI would recommend to stick with default Maven layout ( and also use maven as build tool )
Productive classes / resources:
src/main/java
src/main/resources
Test data and classes:
src/test/java
src/test/resources
Maven can also take care to package your application properly with all the necessary jars ( look for maven assembly plugin )
src/com.enterprise_name.project_name. Main.java (the main class)
src/com.enterprise_name.project_name.model.(here all model classes)
src/com.enterprise_name.project_name.view.(here all view classes, JFrame, Jdialog,etc)
src/com.enterprise_name.project_name.view.resources.(here all the files and images used in the views *note)
src/com.enterprise_name.project_name.controller.(here all controller classes)
lib/(here all the external libraries - dont forget add to build path)
*note if you need some resource file (xml, config file, etc) create a package .resources. in the specific place where do you need (model, controller, view)
what's with a Java project folder structure ?
It depends on the build system in use for the project.
In the days of Ant or if you let the IDE set it up for you without specifying a build, it was mostly:
src/ bin/
Maven and Gradle use the Maven Standard Directory Layout ( https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html )
src
main
{lang}
packages
resources
test
{lang}
packages
resourcesYou can see that when using Gradle for groovy - https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout the lang for the groovy sources is 'groovy'. This is important if you mix groovy, scala, kotlin, and java all in one project. For example (not my project, just one I found out there) https://github.com/bellingard/sample_multi-language-project
More on reddit.comJava Directory Structure - Stack Overflow
Java directory structure
How to create a directory and sub directory structure with java? - Stack Overflow
Videos
So here the thing guys. I'm a data engineer by profession meaning ETL/SQL master. Recently with the explosion of new tools that hit the market in big data, I'm trying to learn Java. The challenge is, wrapping my head around Java folder structure. When I look at code in GitHub for few of the Apache projects like spark/airflow, it's so convoluted and varies by developer. Is there a rule or strategy that's developers commonly follow?
It depends on the build system in use for the project.
In the days of Ant or if you let the IDE set it up for you without specifying a build, it was mostly:
src/
bin/
Maven and Gradle use the Maven Standard Directory Layout ( https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html )
src
main
{lang}
packages
resources
test
{lang}
packages
resources
You can see that when using Gradle for groovy - https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout the lang for the groovy sources is 'groovy'. This is important if you mix groovy, scala, kotlin, and java all in one project. For example (not my project, just one I found out there) https://github.com/bellingard/sample_multi-language-project
The folder structure in the src directory or of the entire project in general? Project source directory is usually driven by the convention of the build tool you're using, like gradle. The folder structure in your src directory is building the package names for your classes. The goal here is to be consistent within an organization and unique so there is little chance of ambiguity when you bring in a lot of external libraries.
-d classes command line switch tells the compiler to store compiled code in classes folder.
See documentation of javac:
-d directory
Set the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d /home/myclasses and the class is called com.mypackage.MyClass, then the class file is called /home/myclasses/com/mypackage/MyClass.class.
If -d is not specified, javac puts the class file in the same directory as the source file.
If you run javac without any arguments, help content gets printed
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...]Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
And -d says -d <directory> Specify where to place generated class files
I find the whole src/main/com/blah/blah absurd. Is there any way I can use a sane structure in Java? For example:
src/Engine/Vector3.java
You can use File.mkdir() or File.mkdirs() to create a directory. Between the two, the latter method is more tolerant and will create all intermediate directories as needed. Also, since I see that you use "\\" in your question, I would suggest using File.separator for a portable path separator string.
Starting from Java 7, you can use the java.nio.file.Files & java.nio.file.Paths classes.
Path path = Paths.get("C:\\Images\\Background\\..\\Foreground\\Necklace\\..\\Earrings\\..\\Etc");
try {
Files.createDirectories(path);
} catch (IOException e) {
System.err.println("Cannot create directories - " + e);
}
This is a tricky solution (because I used only one path to go to the whole structure).
If you don't like tricky solutions, you can use 4 simple paths instead:
Path p1 = Paths.get("C:\\Images\\Background");
Path p2 = Paths.get("C:\\Images\\Foreground\\Necklace");
Path p3 = Paths.get("C:\\Images\\Foreground\\Earrings");
Path p4 = Paths.get("C:\\Images\\Foreground\\Etc");
and then call the createDirectories method for all of them:
Files.createDirectories(p1);
Files.createDirectories(p2);
Files.createDirectories(p3);
Files.createDirectories(p4);