Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to see java source file in Java stack traces

I am working on a web application deployed on a Tomcat server. On my local test system I use Eclipse and the WST to deploy my code to the server. If stack traces are thrown, I can see the source file and line number for each line - as expected.

However, if an exception is thrown on the production system, the source file is unknown, as well as the line number. This is the case only for my own code, for all stack elements in the trace of external libraries the source file and line number is known.

I am compiling my project as follows (using Ant):

<javac srcdir="${src}" destdir="${build}" fork="true" debug="true" debuglevel="lines, vars, source">
    <classpath refid="classpath" />
</javac>

I can absoutely not figure out where the problem is, although it must be super simple to solve.

Thanks for your help!

>> Edit: Some more information about my deployment: I am definately using these Ant targets to create the war file:

<target name="compile" depends="update-dependencies">  
    <mkdir dir="${build}" />
    <javac srcdir="${src}" destdir="${build}" fork="true" debug="true" debuglevel="lines, vars, source">
        <classpath refid="classpath" />
    </javac>
    <javac srcdir="${tests}" destdir="${build}" fork="true" debug="true" debuglevel="lines, vars, source">
        <classpath refid="classpath" />
    </javac>

    <!-- Copy non-java files -->
    <copydir dest="${build}" src="${src}">
        <exclude name="**/*.java"/>
    </copydir>

    <copydir dest="${build}" src="${tests}">
        <exclude name="**/*.java"/>
    </copydir>
</target>


<target name="war" depends="compile">       
    <war destfile="${war.file}" webxml="WebContent/WEB-INF/web.xml">
        <fileset dir="WebContent" />
        <lib dir="${lib}" />
        <classes dir="${build}" />
    </war>
</target>

On the local system I use eclipse to do the deployment for me, so I don't use any of my ant targets. Do I need the .java files in in the deployment maybe?

>> Edit2: Example stack trace (The exception itself is no problem!):

javax.naming.NamingException: Name is not valid
        at org.apache.naming.NamingContext.unbind(NamingContext.java:248)
        at org.apache.naming.NamingContext.unbind(NamingContext.java:282)
        at org.apache.naming.SelectorContext.unbind(SelectorContext.java:256)
        at javax.naming.InitialContext.unbind(InitialContext.java:416)
        at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:139)
        at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:894)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.destroy(AbstractSessionFactoryBean.java:251)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.destroy(LocalSessionFactoryBean.java:899)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:184)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:463)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:431)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1048)
        at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1022)
        at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:970)
        HERE: at my.pkg.ContextLoaderListener.closeWebApplicationContext(Unknown Source)
        HERE: at my.pkg.ContextLoaderListener.contextDestroyed(Unknown Source)
        at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4174)
        at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4778)
        at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
        at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1319)
        at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1290)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:323)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
        at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
        at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:450)
        at org.apache.catalina.core.StandardService.stop(StandardService.java:587)
        at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
        at org.apache.catalina.startup.Catalina.stop(Catalina.java:648)
        at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:692)
like image 699
Erik Avatar asked Jan 20 '23 11:01

Erik


1 Answers

I found the solution - simple and stupid:

In the ant javac step definintion, change the part

debuglevel="lines, vars, source"

to

debuglevel="lines,vars,source" (no spaces)

and it will work.

Erik

like image 56
Erik Avatar answered Feb 20 '23 01:02

Erik