The VMargument values not properly read by log4j2.properties - spring

Spring web application with log4j2 implemented in tomcat 8 running in windows and linux servers.
In windows server
CATALINA_OPTS specified in setenv.bat file
set "CATALINA_OPTS=-DLOG_FOLDER=D:\apache-tomcat-9.0.22\customlog"
log4j2.properties file is inside WEB-INF\classes\config\
appender.rolling.fileName=${sys:LOG_FOLDER}\logger.log
appender.rolling.filePattern=${sys:LOG_FOLDER}\logging-%d{MM-dd-yyyy}-%i.log.gz
In linux server
CATALINA_OPTS specified in setenv.sh file
set "CATALINA_OPTS=-DLOG_FOLDER=/opt/tomcat01/customlog"
log4j2.properties file is inside WEB-INF\classes\config\
appender.rolling.fileName=${env:LOG_FOLDER}/logger.log
appender.rolling.filePattern=${env:LOG_FOLDER}/logging-%d{MM-dd-yyyy}-%i.log.gz
log folder is always created like '${env:LOG_FOLDER}' or '${sys:LOG_FOLDER}'

You should use ${sys:LOG_FOLDER} in both cases:
${sys:property_name} retrieves the Java system property of that name,
${env:variable_name} retrieves the OS environment variable of that name.
See Log4j 2 Lookups for more details.
There are also other problems in your configuration:
if you start Tomcat on Windows as a service, setenv.bat is not used. You should add -DLOG_FOLDER=D:\apache-tomcat-9.0.22\customlog to the Java tab of the Tomcat Monitor application (bin\tomcat<version>w.exe).
on Linux you are using the wrong syntax to modify an environment variable (Microsoft's syntax), use:
export CATALINA_OPTS="-DLOG_FOLDER=/opt/tomcat01/customlog"
instead.
Remark: If you want to use environment variables instead of system properties, you can use:
export LOG_FOLDER="/opt/tomcat01/customlog"
on Linux, while on Windows you need to run:
tomcat10.exe //US ++Environment="LOG_FOLDER=D:\apache-tomcat-9.0.22\customlog"
See Procrun documentation for more details.

Related

Running Tomcat from windows 10 bash shell

I installed tomcat server on windows10 bash shell. Though it says apache is running.. its not opening admin panel in browser. Browser says 'Connection can't be reached'
Have someone tried this ever before? Please share your inputs.
Thank you
I am assuming you are referring to Bash for Windows (Ubuntu) on Windows 10. Yes Tomcat server can be installed and run from Bash for Windows with no need to install Tomcat in the Windows environment.
First, you may want to check if any local server is running on Windows 10 port 8080 - the default port for Tomcat, or whatever port you are configuring Tomcat for.
Second, open BASH for Windows and install Java. I used Oracle Java JDK 8 (http://www.oracle.com/technetwork/java/javase/downloads/index.html) and downloaded the tar.gz file.
Extract the tar.gz and copy to a standard directory like /usr/local/java or in the /opt/ directory for easy access.
Create JAVA_HOME and JRE_HOME environment variables that link to your java location.
I also updated the alternatives to map java, javac, and javaws. You can use this link to assist (http://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre)
Then download the tar.gz of Tomcat. Again, I used Tomcat 8.5 for my scenario and extract the files to your chosen directory.
Last, run the startup script located in the bin folder of the tomcat extracted folder. You should have a working Tomcat version.
Use the curl command to validate - curl localhost:8080
If you want to change the admin privileges, edit the tomcat-users.xml file located in the conf folder within the extracted tomcat directory.
Access to the tomcat server can also be done through the Windows system and not just through the Bash for Windows CLI.
Hope this helps!

How to pass environment variable to Tomcat running as Windows service

I have an application installed in Tomcat that is invoked by the wrapper which sets an environment variable
set FOO=c:\foo
and invokes the startup.bat, and I have a requirement to run Tomcat as windows service.
So far, I tried to set the system environment variable, which did not help.
I tried following the windows service HOWTO appending ++Environment in the registry, so that
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tomcat7\Parameters\ImagePath
looks like this
C:\Apache\Tomcat-7.0.64\bin\Tomcat7.exe //RS//Tomcat7 ++Environment=FOO=c:\foo
That did not help either.
Any suggestions, please
You were almost there. Replace the equal sign with a space in your tomcat7 command, and that should work.
I've just written this up on another question: Setting User Environment Variables for tomcat on Windows
I had to change --JvmOptions of the service.bat file then remove the service and re-install again.
--JvmOptions "-Dspring.profiles.active=pp;-Dcatalina.home=%CATALINA_HOME%;...."
I have a InstallService.bat file. In the file I am first creating the service without specifying the Environment variable and then I am updating the service with the Environment variable specified.This is how the bat file looks like.
tomcat8 //IS//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto
tomcat8 //US//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto --Environment=Key1=Value1;Key2=Value2
It has started working now.

Where to write set JAVA_OPTS in setenv.bat for tomcat 7 windows installation (as a service)

There are various similar questions but none answers where to embed the environment variable. Unfortunately, in my case there is already a file named setenv.bat which contains a lot of code.
There is a lot of code in it. So the question is where do I write (on which line at what place within setenv.bat)
set "JAVA_OPTS=%JAVA_OPTS% -Dblockchain.callbackUrl=http://example.com/"
I wrote it at the beginning of setenv.bat but it doesn't work.
FYI : I installed tomcat using the windows installer, hence, I have tomcat7w.exe
I'm running tomcat as a windows service
I'm trying to access this variable through Spring in my webapp as :
#Value("#{systemProperties['blockchain.callbackUrl']?:'http://localhost:8080/'}")
private String callbackHost;
Update
I tried setting it in catalina.bat, still didn't worked.
When we create a service from Tomcat installation on windows, such parameters have to be defined in service.bat before installing the service with service.bat install command.
--JvmOptions "-Dblockchain.callbackUrl=http://www.example.com/;-Dcatalina.home=%CATALINA_HOME
Add the environment variables to JvmOptions in service.bat as shown above.

Error running Spring Batch Admin on Tomcat 6/7

I am getting this error when running a Spring Batch Admin template project created via STS 3.2 on vanilla Tomcat 6/7 on RedHat Linux:
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [batch-L.properties] cannot be opened because it does not exist
I have no idea where that file is coming from. I tried searching for the file but to no success. Also, I need to add, that when running the same *war file on my local machine, everything works fine.
I will be grateful for any help.
Spring Batch Admin uses a system variable ENVIRONMENT to determine what properties file to load. By default, (if the variable isn't set), it will look for an HSQLDB version named batch-hsqldb.properties. In your case, it looks like the ENVIRONMENT variable is being set to the letter L.

Can't setup remote debugging with JBoss Web 2.1.4 windows and eclipse

I'm unable to find an option to setup remote debugging in JBossWeb 2.1.4 on Windows. It is not installed as a service and there are no .bat scripts where I can edit the JAVA_OPTS environment variable to include:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4142
The only thing in the jboss web bin directory are jbossweb.exe files.
I've tried editing the run configuration in eclipse to start the container by running jbossweb.exe and setting the environment variable JAVA_OPTS to the above, but it doesn't listen on port 4142 on startup (ie, there seems to be no effect in adding the environment variable to the run configuration).
Any ideas here?
If you control the server from eclipse with for instance JBoss Tools, you can just click "debug" instead of "start" in the Server pane in order to start up in debug mode.
You can create such bat script by yourself. Just add jboss.bat file to bin subdirectory of JBoss install directory and put there:
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4142 -jar "D:\JBoss.org\JBoss Web 2.1\bin\bootstrap.jar" start
When you run this script, you will get JBoss running in debug mode. Probably, it won't help you in all situations, but it worked for me.

Resources