Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » "Unknown Source" while using Java to debug and "Stop at main" not working
"Unknown Source" while using Java to debug and "Stop at main" not working [message #989737] Fri, 07 December 2012 13:21 Go to next message
V User is currently offline V UserFriend
Messages: 4
Registered: December 2012
Junior Member
I am experienced programmer/debugger but come from a C++, Visual Studio & windbg debugging background.

This is the first time I am using Eclipse & the first I am debugging a java program with Eclipse.

This is the scenario.

I have a jar file which is my application (c:\work\myapp\myapp.jar)
I have the sources in a separate directory (c:\work\src\)
myapp.jar is run using javaw.exe.

When I run myapp.jar from the command line, this is how I run it

javaw.exe -jar myapp.jar

I don't have a build environment. myapp.jar contains META-INF about the main class inside the jar.

c:\work\src has the source files in the same directory structure in which they were built - i.e. for com.xyz.A, the source file would be c:\work\src\com\xyz\A.java

With great difficulty I have managed to get the jar file to run under the debugger in Eclipse.

This is how I did it.
- I created a debug configuration under Java Application called myapp

These are the settings
1) Main Tab
Project - Empty
Main Class - c:\work\myapp\myapp.jar
Stop in Main is checked

2) Arguments
VM arguments "-jar"

3) JRE
Default(javaw.exe)

4) Classpath - nothing

5) Source - c:\work\src

6) Environment - Empty

When I click on "Debug" from the "Run" menu - my Application launches but it does not break in main - I assumed the "stop at main" option would make it break as soon as main is started - but it didn't so so.

In a window called "Debug", I can see

myapp [Java Application]
"c:\work\myapp\myapp.jar" at localhost:64859
Thread [AWT-Shutdown] (Running)
Daemon Thread [AWT-Windows] (Running)
Thread [AWT-EventQueue-0] (Running)
Thread [Thread-3] (Running)
Thread [DestroyJavaVM] (Running)
Thread [Thread-4] (Running)
C:\Program Files (x86)\java\jre6\bin\javaw.exe



When I right click on the jar line above & chose properties I see the following command line

"C:\Program Files (x86)\java\jre6\bin\javaw.exe" -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:64859 -jar -Dfile.encoding=Cp1252 "\"c:\work\myapp\myapp.jar\""

How do I get my application to stop at main while debugging.

Earlier before I got everything upto this stage, the app threw an exception because of some file it couldn't find - I fixed this by copying the file. When the exception happened, at the call stack - I saw (unknown source) in the line corresponding to my main. So I suspect that even after get my debugger to break in main, I will still not be able connect the debugger to the sources.

Any idea where I am going wrong?
Re: "Unknown Source" while using Java to debug and "Stop at main&quot [message #989751 is a reply to message #989737] Fri, 07 December 2012 14:48 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 12/7/2012 7:10 AM, V User wrote:
> I am experienced programmer/debugger but come from a C++, Visual Studio
> & windbg debugging background.
> This is the first time I am using Eclipse & the first I am debugging a
> java program with Eclipse.
>
> This is the scenario.
>
> I have a jar file which is my application (c:\work\myapp\myapp.jar)
> I have the sources in a separate directory (c:\work\src\)
> myapp.jar is run using javaw.exe.
>
> When I run myapp.jar from the command line, this is how I run it
>
> javaw.exe -jar myapp.jar
>
> I don't have a build environment. myapp.jar contains META-INF about the
> main class inside the jar.
>
> c:\work\src has the source files in the same directory structure in
> which they were built - i.e. for com.xyz.A, the source file would be
> c:\work\src\com\xyz\A.java
>
> With great difficulty I have managed to get the jar file to run under
> the debugger in Eclipse.
>
> [snip]
>
> Any idea where I am going wrong?

It's possible, as you've discovered, to use Eclipse to debug some
remotely running application. It's not the most widespread way of doing
things and is usually reserved for cases, like inter-cooperating
client-server applications where the server is remote.

However, I have to ask why not bring this application into Eclipse
properly and save yourself the trouble especially given that you "own"
the source and can benefit from the tools you get with the Eclipse IDE?
Re: "Unknown Source" while using Java to debug and "Stop at main&quot [message #989770 is a reply to message #989751] Fri, 07 December 2012 16:31 Go to previous messageGo to next message
V User is currently offline V UserFriend
Messages: 4
Registered: December 2012
Junior Member
Russell Bateman wrote on Fri, 07 December 2012 09:48
It's possible, as you've discovered, to use Eclipse to debug some
remotely running application.

The application is not remote - it's running on the same machine as Eclipse & it's eclipse which starting up the application.

Russell Bateman wrote on Fri, 07 December 2012 09:48

However, I have to ask why not bring this application into Eclipse
properly and save yourself the trouble especially given that you "own"
the source and can benefit from the tools you get with the Eclipse IDE?


What exactly do you mean by bring this application into Eclipse properly? Are you saying that I should compile the application using Eclipse - is that a pre-requisite for debugging with Eclipse? The build machine is different & it does nightly automated builds & automated testing.
I don't want to bring that into my debugging machine.

I do this all the time with C/C++ exes. All I need are the exes,dlls, pdbs and sources. And I can launch the exe through Visual Studio & debug it - I have done this also with each and every C/C++ debugger - windbg, gdb etc. And usually the build is done on a different machine without using the IDE.

Can't we do proper debugging with eclipse without integrating the build with Eclipse?

[Updated on: Fri, 07 December 2012 16:34]

Report message to a moderator

Re: "Unknown Source" while using Java to debug and "Stop at m [message #989777 is a reply to message #989770] Fri, 07 December 2012 17:04 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 12/7/2012 9:31 AM, V User wrote:
> Russell Bateman wrote on Fri, 07 December 2012 09:48
>> It's possible, as you've discovered, to use Eclipse to debug some
>> remotely running application.
>
> The application is not remote - it's running on the same machine as
> Eclipse & it's eclipse which starting up the application.

It's "remote" from Eclipse.

> Russell Bateman wrote on Fri, 07 December 2012 09:48
>> However, I have to ask why not bring this application into Eclipse
>> properly and save yourself the trouble especially given that you "own"
>> the source and can benefit from the tools you get with the Eclipse IDE?
>
>
> What exactly do you mean by bring this application into Eclipse
> properly? Are you saying that I should compile the application using
> Eclipse - is that a pre-requisite for debugging with Eclipse? The build
> machine is different & it does nightly automated builds & automated
> testing. I don't want to bring that into my debugging machine.

It's not a complete prerequisite, but given how much easier (you've
already spent more time asking this question than it would have taken to
set the project up in Eclipse) it would be, I just wondered.

Typically, one develops on Eclipse using a source-code control system
such as Git, Subversion, etc. One runs Jenkins, Cruise Control, etc. on
a remote host such that when one pushes code, Jenkins (etc.) kicks off
the build and runs the tests. I rig ours to do nightly builds as well
and, when appropriate, it even deploys. So, yeah, there is process, it
is sophisticated, and it is different from the more ad hoc way you describe.

> I do this all the time with C/C++ exes - I need the exes, pdbs and
> sources. And I can launch the exe through Visual Studio & debug it - I
> have done this also with each and every C/C++ debugger - windbg, gdb etc.
>
> Can't we do proper debugging with eclipse without integrating the build
> with Eclipse?

All I'm saying is how business is ordinarily conducted; it's a cultural
thing. Of course there's always an alternative and someone might come
along here and help you do this your way. What you want to do is far
more achievable for C/C++ development in Eclipse than for Java, it's not
totally impossible, it's not how it's done just as, I'll wager--not
having it done it in a long time and not having done it very long
anyway, developing C# outside of VS might raise eyebrows with developers
asking "Why would you want to do it outside of a good IDE?"

Best of luck to you.
Re: "Unknown Source" while using Java to debug and "Stop at m [message #989789 is a reply to message #989777] Fri, 07 December 2012 19:15 Go to previous messageGo to next message
V User is currently offline V UserFriend
Messages: 4
Registered: December 2012
Junior Member
Russell Bateman wrote on Fri, 07 December 2012 12:04

Typically, one develops on Eclipse using a source-code control system
such as Git, Subversion, etc. One runs Jenkins, Cruise Control, etc. on
a remote host such that when one pushes code, Jenkins (etc.) kicks off
the build and runs the tests. I rig ours to do nightly builds as well
and, when appropriate, it even deploys. So, yeah, there is process, it
is sophisticated, and it is different from the more ad hoc way you describe.


Your way is very good when projects builds in minutes. I have worked on projects which take an hour or more to build and is worked on lots and lots of developers and has tons of make files. I have worked on projects where 22 branches were being developed simultaneously and then merged back to main with automated tests guarding the merges. These automated tests were simultaneously spread across multiple machines & even if one test failed, the checkin wasn't allowed to merge into main. Don't tell me debugging code on the machine on which it's not built is 'not sophisticated'. These projects have used sophisticated version control. It's not fun to build huge projects on an IDE. The code is built on a build machine with the exact same tools which the IDE uses - so I don't see what difference it makes to the IDE if the code is built locally or remotely.


If you think all projects are easy to build - let me introduce you to this very famous book - Large Scale C++ Software Design by John Lakos.
A good part of the book is devoted to designing and writing software in a way that reduces compile, link and build times. People do work on large projects.

The current java code I am trying to debug is not huge - it shouldn't be difficult to build it locally, but I absolutely see no technical reason why Eclipse should not be able to debug code which wasn't built locally.

I guess I am doing something wrong here (and I don't mean not building locally). So if some one could figure out what I am doing wrong, it would be very helpful.
Re: "Unknown Source" while using Java to debug and "Stop at m [message #990055 is a reply to message #989789] Mon, 10 December 2012 16:44 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
You should be able to create a Java Project with no source. Add the jar files to the Build Path by either importing them into the project or as external jars. You can then attach source to the jar files.

Your classes have to be compiled with debugging information in order for debugging to work. Make sure that your build process includes debugging information.
Re: "Unknown Source" while using Java to debug and "Stop at m [message #990065 is a reply to message #990055] Mon, 10 December 2012 17:39 Go to previous messageGo to next message
V User is currently offline V UserFriend
Messages: 4
Registered: December 2012
Junior Member
David Wegener wrote on Mon, 10 December 2012 11:44
You should be able to create a Java Project with no source. Add the jar files to the Build Path by either importing them into the project or as external jars.


The whole application is just 1 jar file - there is no external dependency other than regular java libs. Should I add this jar file into the build path as you suggested above?

David Wegener wrote on Mon, 10 December 2012 11:44

You can then attach source to the jar files.

How do I attach source to the jar files?
Re: "Unknown Source" while using Java to debug and "Stop at m [message #990081 is a reply to message #990065] Mon, 10 December 2012 19:18 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
Yes, add the jar file to the Build Path. Once on the Build Path you can attach source.
Previous Topic:resizing of graphical layout
Next Topic:import pre-existed joomla site in eclipse project
Goto Forum:
  


Current Time: Fri Apr 19 12:00:17 GMT 2024

Powered by FUDForum. Page generated in 0.03369 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top