Stefan Dollase Stefan Dollase - 1 year ago 74
Java Question

Warning: main methods should not be directly called

I currently work on a Java project which has many

methods. Now, I do some refactoring, which affects all
methods. However, some of the
methods are actually called directly from other methods. I think this is bad style and it actually makes the refactoring harder. Thus, I want to be able to identify all places where a
method is called. Currently, I use my IDE tools to find all references to a given
method, however this is tedious and it is easy to forget to check this for one of the

My question is, whether there is some checkstyle rule or Eclipse compiler warnings setting that produces a warning whenever a
method is called directly. I was unable to find one.

Answer Source

As @Jeutnarg suggested in the comments:

[...] you could use Eclipse's Java search. Search for 'main', only searching for 'Method' with Limit to 'References' with Search in 'Sources' with a scope of your project.

This is what I ended up doing and it actually worked much better than I expected.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download