Eclipse remote debug .jar files inside a larger java application

萝らか妹 提交于 2019-12-13 03:29:42

问题


Most of the questions related to remote debugging are for an entire java application from which you have the code on your IDE.

In this case I do not have access to the full application, only to pieces of code, .jar files, that are later on embedded into the larger application which eventually will invoke them and execute their code.

Different from the large application, these .jar files that I develop do not contain the method:

public static void main(string[] args)

The .jar files implement the camel Processor interface which is called when a particular piece of code is required per configuration.

I am trying to set up eclipse remote debugging for the embedded .jar files only. Meaning that once the .jar file code is invoked eclipse IDE would start its debugging process.

What I tried so far:

I tried to start the .jar file in debug mode:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar mycode.jar

After this it starts:

Listening for transport dt_socket at address: 8000

Although as stated above this is not a complete java application and once I try to connect the remote configuration on eclipse to it I get the error:

no main manifest attribute, in mycode.jar

as said before, this made sense to me because I don't have a main class.

Now, is it possible to debug a .jar file only when it is called even if no main class is present?


回答1:


To be honest, I don't think that this is possible. If you want to know that your camel processor is doing the right thing write Unit Tests. Junit is a good framework for that: https://junit.org/junit5/




回答2:


I see four points to note:

1) If you don't have the code, you can't debug inside JARS. You could decompile the JAR and try to debug. See How can we debug a file which is inside Jar file

2) Of course you can debug without a main method if your application is not a desktop standalone app (web service, queue-based app, etc). In that cases you must call the service and the (IDE-known) code will be called, allowing debugging. This applies only if you have the full code of the project, that could be part of a larger application.

3) If you only have pieces of code (functions, or some classes), you can build a unit test (with JUnit or some other software) or a main method setting up ALL NECESSARY values, in order to get a correct program flow. Then, executing the unit test or debugging can do the trick.

4) --Xdebug allows JVM remote debugging, not code debugging. Means you cannot stop in code blocks but basically allows to check the variables, performance specs and more.



来源:https://stackoverflow.com/questions/53067248/eclipse-remote-debug-jar-files-inside-a-larger-java-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!