DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 4)
  • Two Cool Java Frameworks You Probably Don’t Need
  • How To Build Web Service Using Spring Boot 2.x
  • Fighting Fragility With Property-Based Testing

Trending

  • LTS JDK 21 Features
  • AI for Web Devs: Project Introduction and Setup
  • Automated Testing: The Missing Piece of Your CI/CD Puzzle
  • Essential Complexity Is the Developer's Unique Selling Point
  1. DZone
  2. Coding
  3. Java
  4. Problems debugging Java after ANT compile

Problems debugging Java after ANT compile

Alex Staveley user avatar by
Alex Staveley
·
Dec. 14, 11 · Interview
Like (0)
Save
Tweet
Share
8.83K Views

Join the DZone community and get the full member experience.

Join For Free

Ok, this one is pretty easy but worth posting. I lost a few hours because of it and I don't want the same to happen to you! Suppose you want to be able to pass a switch into an ANT target which performs a javac to tell it to include debug information or not.

Your properties file will contain properties such as:

compile.debug=true
compile.debug.level=lines,vars,source

The ANT compile target then uses these properties:
<project default="help" name="my-proj">
 <property file="build.properties"></property>
 ...
 ...
 <target name="compile">
  <echo message="compiling code"></echo>
  <echo message="compile.debug=${compile.debug}"></echo>
  <echo message="compile.debug.level=${compile.debug.level}"></echo>
  <javac srcdir="${SRC.DIR}"
   destdir="${DEST.DIR}"
   debug="${compile.debug}"
   debuglevel="{compile.debug.level}">
   ...
  </javac>
 ...
 ...

However, the debug information is not there when you are debugging.  You run
ant -v compile to get more information. You see:
compile:
     [echo] This target compiles everything.
     [echo] Compiling java classes...
     [echo] compile.debug=true
     [echo] compile.debug.level=lines,vars,source
    [javac] ...
    [javac] Compiling ...
    [javac] Using modern compiler
    [javac] Compilation arguments:
    [javac] '-deprecation'
    [javac] '-d'
    [javac] ...
    [javac] '-classpath'
    [javac] ...
    [javac] '-g:none'
    [javac] '-O'
    [javac]
    [javac] ...
?

Now, as we can see the properties are echo'd as expected.  But, the "-g:none" indicates the compile won't include debug information.  Before you tear your hair out, relax! You have just made a very silly mistake we all make at sometime. When ANT reads property files it reads all property values literally. This means there is a difference between "true" and "true ", i.e. boolean properties should not have trailing spaces otherwise they will not be read as boolean properties. This is what happened here.  Ouch!
Ouch - trailing space!

As it states in http://ant.apache.org/manual/Tasks/property.html, regarding property files: "Trailing spaces are not stripped. It may have been what you wanted."

So rip that trailing space and re-run the ant compile target.

You should see:
[javac] '-g:lines,vars,source'


which means the compiler is going to add lines, vars and source debug information.  Happy debugging!


References:
1. http://ant.apache.org/manual/Tasks/property.html

 

From http://dublintech.blogspot.com/2011/10/problems-debugging-java-after-ant.html

Property (programming) Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 4)
  • Two Cool Java Frameworks You Probably Don’t Need
  • How To Build Web Service Using Spring Boot 2.x
  • Fighting Fragility With Property-Based Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: