Partner – Orkes – NPI EA (cat=Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag=Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Partner – LambdaTest – NPI EA (cat=Testing)
announcement - icon

Browser testing is essential if you have a website or web applications that users interact with. Manual testing can be very helpful to an extent, but given the multiple browsers available, not to mention versions and operating system, testing everything manually becomes time-consuming and repetitive.

To help automate this process, Selenium is a popular choice for developers, as an open-source tool with a large and active community. What's more, we can further scale our automation testing by running on theLambdaTest cloud-based testing platform.

Read more through our step-by-step tutorial on how to set up Selenium tests with Java and run them on LambdaTest:

>> Automated Browser Testing With Selenium

Partner – Orkes – NPI EA (cat=Java)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

1. Overview

In some special circumstances, we don’t have a third-party build tool installed, such as Ant or Maven. And, we still need to compile a project with lots of packages and classes.

In this tutorial, we’re going to use the javac command to accomplish this task with different scenarios.

2. Using File Names

Let’s assume we have two directories in the current directory: src and out. The src directory holds our Java source files, and the out directory will contain the corresponding compiled class files.

Let’s start with a simple scenario. The src directory contains a single Java source file named com/baeldung/MyClass.java:

2 javac compile all java source files in a directory structure 01

Then, let’s use javac to compile the MyClass.java file into the out directory:

$ javac -d ./out/ ./src/com/baeldung/MyClass.java

In the above command, the -d option specifies the destination directory for the class file. Also, we should note that the exact code of the MyClass.java file isn’t that important, and we only need to ensure it’s a grammar-correct Java file.

To be a little complicated, let’s add another three Java files – YourClass.java, HerClass.java, and HisClass.java:

javac compile all java source files in a directory structure 02

To compile all four of the above Java files, we can list each of them on the command line:

$ javac -d ./out/ \
./src/com/baeldung/MyClass.java \
./src/com/baeldung/YourClass.java \
./src/com/baeldung/HerClass.java \
./src/com/baeldung/HisClass.java

Then, let’s add a new Main.java file that refers to the other four Java files, for example, by invoking methods or creating an object instance:2 javac compile all java source files in a directory structure 03

In this case, we only need to compile the Main.java file:

$ javac -sourcepath ./src/ -d ./out/ ./src/com/baeldung/Main.java

After the above command, the other four class files will also be compiled. That’s because javac will search for the required types and compile the corresponding source files by default. If we don’t want to compile the required types, we can add the -implicit:none option.

The -sourcepath option tells the Java compiler where to find the input source files. If the -sourcepath option isn’t specified, javac will utilize the user classpath to search for both the class files and source files. So, we can replace the -sourcepath option with the -classpath or -cp option:

$ javac -cp ./src/ -d ./out/ ./src/com/baeldung/Main.java

However, this approach has its limitations: the javac command only compiles the required types and omits other source files. For example, if we add a new ItsClass.java and the Main.java doesn’t refer to it, then ItsClass.java will not be compiled:

2 javac compile all java source files in a directory structure 04

To summarize, there are two scenarios suitable to list filenames in the javac command line: when there are just a few Java source files, and when there is a launcher class that refers to other classes recursively.

3. Using Wildcard

The javac command also supports the wildcard character (*) for compiling multiple source files in the same directory.

For example, we can use the wildcard to compile the above source files:

$ javac -d ./out/ ./src/com/baeldung/*.java

To complicate our scenario further, let’s add four sub-packages (spring, summer, autumn, and winter) and corresponding classes:

javac compile all java source files in a directory structure 05

Now, in the command line, we can list each package with a wildcard to compile all of them:

$ javac -d ./out/ \
./src/com/baeldung/*.java \
./src/com/baeldung/spring/*.java \
./src/com/baeldung/summer/*.java \
./src/com/baeldung/autumn/*.java \
./src/com/baeldung/winter/*.java

When there are only a few packages, regardless of the source file number, it’s suitable to use this wildcard approach.

4. Using Argument Files

When there are multiple packages to compile, then using the javac command with an argument file comes in handy. An argument file can include both the javac options and source file names.

To use an argument file, we need to prepend the at sign (@) leading character before the argument filename:

$ javac -d ./out/ @sources.txt

But how can we generate such a @sources.txt file? That depends on the OS we’re using. In Linux or macOS, we can use the find command:

$ find ./src/ -type f -name "*.java" > sources.txt

In the above command line, the ./src/ is our search starting-point directory, the -type f option filters only regular files, and the -name “*.java” option matches all filenames with the .java extension.

However, in Windows, we can use the dir command:

> dir src /b /s *.java > sources.txt

In the above command line, the src folder is our search path, the /b switch shows the directory and file names without additional information, and the /s option lists all files in a specified directory and all subdirectories.

The shortcoming of this approach is that each time we add a new or remove an existing Java source file, we need to regenerate the sources.txt file.

5. Other Approaches

Besides the above common approaches, there also exist other OS-dependent approaches, such as using globstar or pipe.

5.1. Using Globstar

Bash version 4.0 adds a new globbing option called globstar that treats the double wildcard (**) differently. With it enabled, Bash will traverse multi-level directories; otherwise, Bash will only search a single-level directory.

However, this option is disabled by default. And, we can use the shopt (sh + opt, shell options) command to inspect the Bash option settings. If we execute the shopt command without any argument, it will output a long list of options and their statuses (on or off).

Currently, we’re only concerned with the globstar option:

$ shopt globstar
globstar       	off

To enable it, we use the shopt command with the -s option:

$ shopt -s globstar

To disable it, we invoke the shopt command with the -u option:

$ shopt -u globstar

After enabling this option, we can invoke javac with the double wildcard:

$ javac -d ./out/ ./src/**/*.java

5.2. Using a Pipe

Conceptually, a pipe is a connection between two processes. And, we can utilize this pipe mechanism to connect multiple commands to produce our desired results.

To compile our Java source files, we can combine the find, xargs, and javac commands:

$ find ./src/ -type f -name "*.java" | xargs javac -cp ./src/ -d ./out/

Also, the find command supports the -exec action:

$ find ./src/ -type f -name "*.java" -exec javac -cp ./src/ -d ./out/ '{}' ';'

The above command line may run a bit slowly. That’s because the javac command will run for each matched file. For more information, we can use the man find command to read the -exec option’s documentation.

To be a little faster, we can change the semicolon (;) into a plus sign (+). Then, the javac command will collect all the matched files and execute only once:

$ find ./src/ -type f -name "*.java" -exec javac -cp ./src/ -d ./out/ '{}' +

6. Conclusion

In this article, we first looked at some common approaches to compiling all Java source files in a directory structure, such as using filenames, wildcards, and an argument file. Then, we looked at some OS-dependent approaches, such as using globstar and pipe.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

Partner – Orkes – NPI EA (cat = Spring)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

Partner – Orkes – NPI EA (tag = Microservices)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – LS – NPI (cat=Java)
announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

eBook Jackson – NPI EA – 3 (cat = Jackson)