Bug 66507 - Catalina version command not honoring JAVA_OPTS variable
Summary: Catalina version command not honoring JAVA_OPTS variable
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.x
Hardware: All All
: P2 minor with 5 votes (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-02 15:29 UTC by Eric Hamilton
Modified: 2023-04-26 09:14 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Hamilton 2023-03-02 15:29:36 UTC
The catalina version command is ignoring the JAVA_OPTS variable, in contrast to the variable documentation.  This is observed in both the .sh and .bat scripts.


Documentation of JAVA_OPTS:
"... Include here and not in CATALINA_OPTS all options, that should be used by Tomcat and also by the stop process, the version command etc. ..."


Linux use case:
export JAVA_OPTS=-XshowSettings
catalina.sh version

Windows use case:
SET JAVA_OPTS=-XshowSettings
catalina.bat version

Observed the catalina version command did not output additional JVM settings information.

Expected the catalina version command to honor the configured JAVA_OPTS variable.


Suggested catalina.sh fix:
elif [ "$1" = "version" ] ; then

    "$_RUNJAVA" "$JAVA_OPTS" \
      -classpath "$CATALINA_HOME/lib/catalina.jar" \
      org.apache.catalina.util.ServerInfo

else


Suggested catalina.bat fix:
:doVersion
%_EXECJAVA% %JAVA_OPTS% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
goto end
Comment 1 Eric Hamilton 2023-03-06 14:51:43 UTC
Updated suggested catalina.sh fix to conform with execution style of other commands:
elif [ "$1" = "version" ] ; then

    eval "\"$_RUNJAVA\"" "$JAVA_OPTS" \
      -classpath "\"$CATALINA_HOME/lib/catalina.jar\"" \
      org.apache.catalina.util.ServerInfo

else
Comment 2 Han Li 2023-03-07 03:40:07 UTC
Thanks for reporting this.

Fixed in:
- 11.0.x for 11.0.0-M5 onwards
- 10.1.x for 10.1.8 onwards
- 9.0.x for 9.0.74 onwards
- 8.5.x for 8.5.88 onwards
Comment 3 Thomas Starlinger 2023-04-24 13:04:42 UTC
Hi.

We're using an RMI agent to let JConsole connect to the Tomcat JVM. The agent is configured via JAVA_OPTS. Now, if I try to start version.sh resp. catalina.sh the system tries to start the agent which in turn tries to open a port and that fails because the port is already in use.

-------------8<-------------8<-------------8<-------------
Create RMI registry on port 8112
Exception in thread "main" java.lang.reflect.InvocationTargetException
 :
Caused by: java.rmi.server.ExportException: Port already in use: 8112; nested exception is:
        java.net.BindException: Address already in use
 :
-------------8<-------------8<-------------8<-------------

Is there any method to do this without triggering the BindException?

Regards

Thomas
Comment 4 Eric Hamilton 2023-04-24 13:35:53 UTC
Thomas,
Can you try moving the agent configuration to the CATALINA_OPTS variable?

The CATALINA_OPTS variable is only used by the commands that start the Tomcat server, while the JAVA_OPTS variable is used for all Java commands.
Comment 5 Thomas Starlinger 2023-04-26 09:14:42 UTC
(In reply to Eric Hamilton from comment #4)
> Thomas,
> Can you try moving the agent configuration to the CATALINA_OPTS variable?
> 
> The CATALINA_OPTS variable is only used by the commands that start the
> Tomcat server, while the JAVA_OPTS variable is used for all Java commands.

That seems to work. Thank you very much for the pointer