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

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.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

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

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Introduction

When working on Java projects in Eclipse, maintaining a consistent code style is important for readability. However, strict formatting isn’t always ideal. Some projects require disabling automatic formatting entirely, while others need a way to preserve the layout of specific code blocks, such as complex SQL queries or mathematical matrices.

Eclipse offers precise control over its code formatter. We can manage formatting at a global level, or through dedicated formatters “off” tags.

In this tutorial, we’ll explore the different ways to disable and control the Eclipse code formatter so it fits our specific workflow.

2. Why Controlling Formatting in Eclipse Matters

While automatic formatting in Eclipse streamlines our workflow and maintains consistency, it can occasionally compromise readability in specialized scenarios. We often find that standard reformatting rules can unintentionally collapse multi-line SQL queries, misalign manual tables, or distort ASCII diagrams that were carefully crafted for documentation.

Beyond visual clarity, maintaining control over the formatter is essential for clean version control; it prevents formatting noise in our commits, ensuring that code reviews focus on logic changes rather than white-space adjustments. Managing these settings helps us keep our code clear and professional, even in complex projects.

3. Disabling Automatic Formatting Globally

Eclipse enables us to disable formatting across the entire project. To do this, we hover over Window and select Preferences:

open eclipse preferences

Next, we go to Java > Editor > Save Actions and uncheck Format source code to prevent Eclipse from reformatting files automatically when we save them:

disable global formatting eclipse 1

These settings provide global control and allow us to focus on writing clean code without unexpected changes.

4. Preserving Custom Formatting for Specific Sections

Sometimes, we want certain sections of our code to retain their unique layout while the rest follows standard project rules. Eclipse provides formatter on/off tags for these situations. These tags act as a shield, instructing the IDE to ignore specific blocks and keep our manual formatting intact.

Before we can use them, we must ensure these tags are enabled in our preferences. To verify this, we navigate to Window > Preferences, then go to Java > Code Style > Formatter:

disable global formatting eclipse 1

From here, we select our Active profile and click the Edit button:

select active profile to edit

Under the Off/On Tags tab, we check the box to enable the tags. We can use the default @formatter:off and @formatter:on tags or customize them to match our team’s specific conventions:

enable on off tags in eclipse

Once enabled, we can wrap our code to protect a specific block:

// @formatter:off
public void myCustomFormattedSection() {
//Code here keeps its formatting
}
// @formatter:on

Everything we place between these tags remains exactly as written. This method is ideal for scenarios where vertical alignment is critical, such as when we are defining a matrix or a grid.

For example, by wrapping a LAYOUT_GRID within these tags, we create a “protected zone” that prevents Eclipse from collapsing our rows into a single, unreadable line:

formatting a matrix in eclipse

This ensures that the visual structure we intended remains preserved every time we save.

5. Practical Techniques to Fine-Tune Eclipse Formatting

We can further refine how Eclipse treats our code by using a few built-in hacks that don’t always require turning the formatter completely off.

5.1. Preserving Manual Line Breaks

One of the most helpful settings we can enable is Never join already wrapped lines. We find this under Java > Code Style > Formatter > Edit > Line Wrapping:

Preserving Manual Line Breaks

When we check this box, Eclipse still formats our code (like fixing indentation), but it respects the manual line breaks we’ve already created. This is a great middle ground that keeps our code consistent without squashing our logical groupings.

5.2. The Trailing Comment Trick

For structure-heavy code like matrices or arrays, we can use a trailing comment trick to force the formatter to keep our lines separate. We can add a line comment (//) at the end of each row to instruct Eclipse that the line is finished. This prevents it from merging the rows into a single, long line:

trailing comment trick

While this keeps our lines readable without using @formatter:off tags, we should use it carefully, as it can make the code look a bit cluttered with empty comments.

5.3. Customizing Tag Names

Finally, if we find that @formatter:off is too generic or doesn’t match our team’s style, we can rename these tags in the Off/On Tags settings. For instance, we might rename them to //@stop-format and //@start-format to make our intentions even clearer to other developers on the team:

customizing tag names

6. Best Practices for Managing the Eclipse Formatter

To keep our workflow smooth and our codebase clean, we should follow these strategic practices:

  • The @formatter:off must be used only when necessary, such as for complex matrices or multi-line queries. This way, our code doesn’t become cluttered with tags, and the majority of our file remains clean and standardized.
  • Since these settings are IDE-specific, we make sure everyone on our team has Enable Off/On tags checked. This prevents one of us from unintentionally reformatting another’s carefully aligned protected zone.
  • Finally, after updating our settings, we must perform a quick test by manually formatting a file with Ctrl+Shift+F. Doing this confirms that Eclipse follows our rules before committing changes to version control.

7. Conclusion

In this article, we explored how to manage and selectively disable the Eclipse code formatter to fit specific development needs.

We discussed disabling automatic formatting globally through Save Actions, using @formatter:off tags for precise block-level control, and applying advanced techniques like preserving manual line breaks and the trailing comment trick.

These controls allow us to handle complex code structures while keeping our Java code clean, readable, and professional.

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.

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.

eBook Jackson – NPI EA – 3 (cat = Jackson)
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments