Solved

Ant compiled program not showing source code line in errors

Posted on 2004-10-04
6
275 Views
Last Modified: 2012-05-05
When i compile my program and build the jar package using ant, and then execute that jar package and hit an error, the displayed java error doesnt seem to know about the source code.  It prints out the stack trace, but doesnt include any line numbers so i dont really know where the error was. When i run the same code in my IDE, JBuilder, and hit an error, it always tells me where in the source code the error was. Here is my build.xml file for my package. Any suggestions on what to change so it can reference the source code line number when errors occur?

<?xml version="1.0"?>
<project default="dist" name="Project Eric">
     <description>Stat Program</description>

    <property name="srcDir" location="/usr/local/jakarta/webapps/NBNFBA/WEB-INF/src"/>
    <property name="buildDir" location="build"/>
    <property name="distDir" location="dist"/>
    <property name="tomcat.lib.dir" value="/usr/local/jakarta/common/lib"/>
    <property name="mysql.lib.dir" value="/Library/Java/Extensions"/>

    <path id="java.libs">
      <fileset dir="${tomcat.lib.dir}" includes="servlet-api.jar"/>
      <fileset dir="${tomcat.lib.dir}" includes="mail.jar"/>
      <fileset dir="${tomcat.lib.dir}" includes="activation.jar"/>
      <fileset dir="${mysql.lib.dir}" includes="mysql-connector-java-3.0.10-stable-bin.jar"/>
      </path>

    <target name="init">
       <tstamp/>
       <mkdir dir="${buildDir}"/>
       <mkdir dir="${distDir}"/>
    </target>

    <target name="compile" depends="init">
       <javac srcdir="${srcDir}" destdir="${buildDir}" classpathref="java.libs"/>
    </target>

    <target name="dist" depends="compile">
       <jar destfile="${distDir}/package-${DSTAMP}.jar" basedir="${buildDir}">
         <manifest>
           <attribute name="Built-By" value="${user.name}"/>
           <attribute name="Main-Class" value="fantasy.gui.Main"/>
           <attribute name="Class-Path" value="mail.jar activation.jar servlet-api.jar mysql-connector-java-3.0.10-stable-bin.jar "/>
           </manifest>
       </jar>
       <jar destfile="${distDir}/package-src-${DSTAMP}.jar" basedir="${srcDir}"/>
    </target>

    <target name="clean">
      <delete dir="${buildDir}"/>
      <delete dir="${distDir}"/>
    </target>
</project>

0
Comment
Question by:Hokester
6 Comments
 
LVL 4

Accepted Solution

by:
gdrnec earned 150 total points
ID: 12217767
In your compile task use:

<javac srcdir="${srcDir}" destdir="${buildDir}" classpathref="java.libs" debug="on"/>

I think this works to give you better line info
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12217860
check the dir where the source code is. Maybe it is unreachable.
0
 

Author Comment

by:Hokester
ID: 12217938
i know the source code is reachable because the compile works and the package is successfully built.  ill give the debug try an attempt tonight when i get home.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 4

Expert Comment

by:gdrnec
ID: 12218059
Good luck.
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12219398
hi
u can try like this

 <javac srcdir="../com/xxx/xxx/xxx/dao" destdir="${build.jar}/classes"
                    debug="true" debuglevel="lines,vars,source"/>  

this will show you the line number when u use the classes anywhere.

thanks
Kiran
0
 

Author Comment

by:Hokester
ID: 12232780
gdrnec,
this worked exactly like i wanted it to. Now that i knew the command i found all kinds of information about what you said in the ant documentation.  kiranhk, i gave the points to gdrnec because you mostly said the same thing, he just beat you to it.  It is worth noting that if anyone reads this in the future that i had to delete my build directory because the files needed rebuilt using this debug on feature. When i originally tried the solution it did not work. I deleted the build directory, so that everything had to be rebuilt, and then it worked just like i wanted.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now