JavaCodePrinter is a Java utility that scans a specified directory and its subdirectories for .java files, collating their contents into a single text file. This tool is particularly useful for developers, educators, and students who need to consolidate Java source code for analysis, sharing, or archiving purposes.
This project is open-source and licensed under the MIT License, allowing you to use, modify, and distribute the code as you wish, provided you include the original copyright.
We welcome contributions through pull requests and encourage you to report any issues on the Issues board.
- Java SE 17 or higher installed on your computer.
- Verify your Java version by running
java --versionin your terminal.
- Verify your Java version by running
-
Clone or Download the repository to your local machine.
-
Navigate to the directory containing
JavaCodePrinter.javain your terminal. -
Compile the Java file using the following command:
javac JavaCodePrinter.java
This will generate a
JavaCodePrinter.classfile in the same directory.
By default, the program scans the current working directory and its subdirectories, excluding certain directories like build, test, and .git. It collates all .java files into a single text file named code.txt.
To run the program from the directory containing the JavaCodePrinter.class file:
java JavaCodePrinterTo specify a custom output file name, provide it as an argument:
java JavaCodePrinter output_filename.txtTo run JavaCodePrinter from any directory in your terminal, you can add its location to your system's environment variables.
-
Add the Directory to CLASSPATH
-
On Windows:
set CLASSPATH=%CLASSPATH%;C:\path\to\directory
-
On Unix/Linux/MacOS:
export CLASSPATH=$CLASSPATH:/path/to/directory
Replace
C:\path\to\directoryor/path/to/directorywith the actual path to the directory containingJavaCodePrinter.class. -
-
Move the Class File to a Common Directory (Optional)
Alternatively, you can place the
JavaCodePrinter.classfile in a directory that's already included in yourCLASSPATH. -
Run the Program from Any Location
Now, you can run
JavaCodePrinterfrom any directory:java JavaCodePrinter
Remember that the program operates on the current working directory from which it is run.
- Excluding Directories: The program automatically excludes certain common directories to prevent including unwanted files, such as compiled classes or test suites.
- Charset Specification: The program uses UTF-8 encoding when reading and writing files to ensure proper handling of special characters.
- Progress Indicators: The program displays progress in the console, showing the number of files processed and lines of code.
- Data Summary: At the end of processing, the program outputs a summary of the total number of Java files and lines of code.
- Java SE 17 or higher installed on your computer.
- Works on Windows, macOS, and Linux systems.
-
Learning & Teaching: Educators and students can compile all
.javafiles into one file for easier reading, sharing, and analysis. -
Code Portability for Assistance: Easily share your entire Java project's source code with a teacher, tutor, or AI coding assistant without managing multiple files.
-
Easier Code Metrics: Run metrics on the whole project (e.g., lines of code, number of methods/classes) to get an overview of the code's size and complexity.
-
Quick Project Overview: Produce a single file containing all the Java code, making it easier to review the codebase, especially for new team members.
-
Integration with Other Tools: Integrate with tools that require a single source file for features like code formatting, highlighting, or converting to different formats (e.g., PDF).
-
Audit & Compliance: Simplify the audit process by providing a consolidated view of the code for compliance checks.
-
Simple Text Backup: Create a single text file backup of your Java project's source code as a snapshot in time.
This project is licensed under the MIT License. You are free to use, modify, and distribute the code, provided you include the original license notice in any copy of the software/source.
We welcome contributions to this project! If you have a feature request, bug report, or want to improve the code, please feel free to:
- Open an Issue: Use the Issues board to report bugs or suggest features.
- Submit a Pull Request: Fork the repository, make your changes, and submit a pull request for review.
Please ensure your code adheres to the project's coding standards and include appropriate documentation and tests.
Thank you for using JavaCodePrinter! If you find this tool helpful, please consider starring the repository and sharing it with others.
- Author: Ben Lamb ([email protected])
- GitHub Repo: https://github.com/benlambm/java-code-printer