(Ehum, cough, cough, ohh boy, I just hope no one pays attention to my 
incompetence.)

Sirs, thank you for your patience. Let's do some easy examples, and forget 
about everything else. I fully understand that the main class needs to have 
a main method to start the application. I have also read your manuals for 
the agent and the cli, so I quite know how to use them, but am a bit, 
maybe, confused, how the agent works.

I have a simple java application, HelloWorld.class which consists of a 
class and a main method that waits for an input:

System.out.println("Say something:");
System.console().readLine();

Normal scenario to invoke your agent would be java -javaagent:agent.jar
=address=localhost,port=500,output=tcpserver HelloWorld
This will make a successful code coverage due to the application is 
constantly running until input.

Now, would the same scenario be possible without a java class? java -
javaagent:agent.jar=[options]

Next example, to understand better with simple examples provided (and this 
does not mean that you have misunderstood me), if the above java 
application is already running without the agent, would it be possible to 
attach this agent to this application without providing any class? Or, when 
I start any java application, I also need to start the agent simultaneously 
with the application so he can listen on the ip and port, otherwise, he 
will not have any connection whatsoever to that simple application?

Please forgive me if I am just confusing everything, because personally I 
believe the agent simultaneously needs to be provided a class as an 
argument to the jvm (java -javaagent:agent.jar=[options] class).


Den fredag 3 april 2020 kl. 17:55:13 UTC+2 skrev Evgeny Mandrikov:
>
>
>
> On Friday, April 3, 2020 at 12:18:14 PM UTC+2, [email protected] 
> <javascript:> wrote:
>>
>> Please forgive me my stupidity. Your last comment, nr. 3, can you start 
>> the agent without using a main class? E.g. a normal scenario as I've 
>> interpreted the agent would be, java- javaagent:/jacocoagent.jar=[options] 
>> com.example.myapp.HelloWorld, but is it possible to start the agent through 
>> Dockerfile with a CMD ["sh", "-c", "./script.bash [similar to the above for 
>> the jacocoagent]"] without adding any main class to the jvm? With other 
>> words, if you have a docker container running a java application, can you 
>> trigger the agent with the CMD above without adding any main class or must 
>> you always provide a main class to be added to the jacocoagent so it can do 
>> the coverage?
>>
>
> Let me quote some page from many on the internet - 
> https://www.journaldev.com/12552/public-static-void-main-string-args-java-main-method
> Java main method is the entry point of *any java program*.
>
> Back to your example this means that your application already has main 
> class.
> And somewhere in your "script.bash" there is already command "java".
> Whether or not and how you can pass "-javaagent" from cmd that calls 
> "script.bash" down to this "java" command is not a question for JaCoCo 
> developers, but for developers of your "script.bash" - please talk with 
> them.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/77da84cd-5fce-4afa-b927-3622acf9e1fb%40googlegroups.com.

Reply via email to