Repository: pinpoint-apm/pinpoint
Issue: Add better logging for when application's main class cannot be deduced from properties
Labels: enhancement

#### Description
The application's main class is currently deduced by reading in `sun.java.command` property. For Java versions prior to 1.6.0_25, this property is not present (other JVMs may not have this at all).
The log should be improved when this property is not found to let users spot the problem easier and to possibly let them know of a solution/workaround.
(Looking through the call stack to retrieve the main class would be another option but this is a different issue entirely)


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/MainClassCondition.java b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/MainClassCondition.java
index 71343f464083..9d237fbd3d1e 100644
--- a/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/MainClassCondition.java
+++ b/bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/MainClassCondition.java
@@ -21,6 +21,7 @@
 
 import com.navercorp.pinpoint.bootstrap.logging.PLogger;
 import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
+import com.navercorp.pinpoint.common.util.JvmUtils;
 import com.navercorp.pinpoint.common.util.SimpleProperty;
 import com.navercorp.pinpoint.common.util.SystemProperty;
 import com.navercorp.pinpoint.common.util.SystemPropertyKey;
@@ -47,6 +48,12 @@ public MainClassCondition(SimpleProperty property) {
             throw new IllegalArgumentException("properties should not be null");
         }
         this.applicationMainClassName = getMainClassName(property);
+        if (this.applicationMainClassName == NOT_FOUND) {
+            logger.info("Main class could not be deduced, please set 'profiler.applicationservertype' in pinpoint.config.");
+            logger.info("If you're running on 1.6.0_24 or prior version of Java, consider upgrading to 1.6.0_25+.");
+            logger.info("If you're running Tomcat or Tomcat on Spring Boot, please set 'profiler.tomcat.conditional.transform' to false");
+            logger.info("If you're running Jboss, please set 'profiler.tomcat.conditional.transform' to false");
+        }
     }
 
     /**
@@ -87,7 +94,8 @@ public String getValue() {
     private String getMainClassName(SimpleProperty property) {
         String javaCommand = property.getProperty(SystemPropertyKey.SUN_JAVA_COMMAND.getKey(), "").split(" ")[0];
         if (javaCommand.isEmpty()) {
-            logger.warn("Error retrieving main class from [{}]", property.getClass().getName());
+            String jreVersion = property.getProperty(SystemPropertyKey.JAVA_RUNTIME_VERSION.getKey());
+            logger.warn("Error retrieving main class using '{}', jre : {}", SystemPropertyKey.SUN_JAVA_COMMAND.getKey(), jreVersion);
             return NOT_FOUND;
         } else {
             JarFile executableArchive = null;
@@ -100,7 +108,7 @@ private String getMainClassName(SimpleProperty property) {
                 return javaCommand;
             } catch (Exception e) {
                 // fail-safe, application shouldn't not start because of this
-                logger.warn("Error retrieving main class from java command : [{}]", javaCommand, e);
+                logger.warn("Error retrieving main class", e);
                 return NOT_FOUND;
             } finally {
                 if (executableArchive != null) {


Test patch: