I need to pass a couple of JVM arguments to the JVM which Tomcat is running in so that my application can pick them up.
I want to follow the process outlined in this article to pick up environment variables.
How would I go about doing this?
UPDATE
Sorry This is running under windows (7 on my Dev machine 2003 on client server)
Windows:
In your Tomcat /bin folder, you should have a tomcat5w.exe admin app (or in later versions tomcat6w.ex, tomcat8w.exe, etc). Go to the Java tab and add the args in the "Java Options:" box.
Note that when you add new args, you need to add them as NEW LINES in that box (above or below any others there), not as additional arguments IN FRONT or BACK of values on one of the existing lines.
Linux / UNIX:
In *nix, changes to the setenv.sh file should be picked up:
export JAVA_OPTS=-server -Xms2g -Xmx4g -XX:PermSize=64m -XX:MaxPermSize=256m $JAVA_OPTS
Don't touch catalina.sh or other files in bin
You need to edit the Windows service. There are three ways to do this:
Start Tomcat5w with //MS//ServiceName to get an icon in the system tray which gives you a quick access to the configuration of the service.
Open the service manager in the "Control Panel". There is an entry for Tomcat.
In the editor, there is a tab where you can add additional JVM parameters.
The third way (which I prefer) is to write a script which edits the config for you. This way, you can save the config somewhere for backup. See the docs how to do that (Hint: use tomcat5 //US//...)
Related
I've been trying to automate the creation of our development environment by combining batch files and WLST, but I am struggling to change the memory WebLogic server will start with.
Currently we are manually changing the memory settings in the <DOMAIN_HOME>/bin/setDomainEnv.cmd script, but this is a workaround. It should be possible to to do it automatically without much effort.
Setting the Domain
The script that sets the Domain in pretty simple:
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_45
set MW_HOME=C:\dev\wls1036_dev
set DOMAIN_HOME=C:\dev\domain
cd %MW_HOME%
call configure.cmd
mkdir %DOMAIN_HOME%
cd %DOMAIN_HOME%
%JAVA_HOME%\bin\java.exe -Xmx1024m -XX:MaxPermSize=256m -Dweblogic.management.username=weblogic -Dweblogic.management.password=welcome1 weblogic.Server
I've tried to use some variables in this script such as MEM_ARGS, JAVA_OPTIONS, but none of these are forwarded to the final configuration of the domain, later it always starts with 512 heap, and 128 perm, which are not enough.
WLST memory start args
We are using Eclipse, and it does call the startWebLogic.cmd as start script. It is the standard configuration.
I tried to use the following WLST script. It does set the server start arguments, but WebLogic is not using those properties and loads not enough memory.
edit()
startEdit()
cd('/Servers/myserver/ServerStart/myserver')
cmo.setArguments('-Xmx1024m -XX:MaxPermSize=256m')
activate()
Any ideas?
You can use the trick for getting ServerStart arguments:
Write simple offline WLST-script to get arguments from config.xml:
getArguments.py
import sys
readDomain(sys.argv[1])
cd('Server/%s/ServerStart/NO_NAME_0' % sys.argv[2])
argsFile = open('arguments.txt', 'w')
print >>argsFile, cmo.arguments
Add this script to startWeblogic.cmd like:
startWebLogic.cmd
...
set DOMAIN_HOME=%~dp0
path\to\wlst.cmd getArguments.py %DOMAIN_HOME% admin_server_name
set /p EXTRA_JAVA_PROPERTIES=<arguments.txt
call "%DOMAIN_HOME%\bin\startWebLogic.cmd" %*
There is no easy way of setting values when executing WebLogic from Eclipse. It'll call the batch script and, at least at current version, does not allow to send dynamic parameters.
We solved it making the setDomainEnv.cmd file part of our versioned configuration:
Copy the setDomainEnv.cmd file to your version control configuration.
Edit whatever you want (memory, etc)
Copy the file like copy custom\setDomainEnv.cmd %DOMAIN_HOME%\bin /y when running your development environment configuration script.
Now every time you configure your development environment memory values will be ready without manual intervention.
You have to reedit your stuff when updating WebLogic, so you don't end up with an outdated component.
I would like to monitor a local Java application using JVisualVM. When I'm starting it, the popup 'Local java application cannot be monitored' or 'Local Applications Cannot Be Detected' is shown. I have read here that it is a permissions problem. Every time when I grant full access to folder %TMP%hsperfdata_MY_USER_ID to me (logged user) and everyone (windows user), the permissions are reset when I start JVisualVM.
I know that another solution is to delete hsperfdata_MY_USER_ID, but why does the permissions trick not work? Is the permissions folder reset a Windows feature?
System : Windows 7
Tested on cmd started as administrator. I use the same accounts and I do not pass any JVM parameters such as com.sun.management.jmxremote.port=XXXX.
For people stumbling here who have a FAT-type file system:
Make a directory (e.g. e:\temp) on an NTFS disk.
Start both java and jvisualvm with an environment variable TMP=E:\temp.
There are three options to set the environment variable for java:
In your IDE, go to the project options or launch options and find the 'Environment' entry, then enter TMP=E:\temp
Open a cmd prompt, and execute set TMP=E:\temp before launching youur java application from the same prompt.
Put the two lines you'd enter at the cmd prompt in a .bat file. Optinally add pause at the end of the bat file to prevent the console window from disappearing in case of a runtime exception or vm crash.
Similarly, for JVisualVM, use one of the last two options.
I had the 'Local Applications Cannot Be Monitored' problem, got it solved like this:
Exit all java processes
Delete existing folder %TMP%\hsperfdata_username
Start jvisualvm, which created the folder with a different casing: %TMP%\hsperfdata_USERNAME
My problem and solution have nothing to do with permissions, so may not work for the original problem in the question.
Also see https://visualvm.github.io/troubleshooting.html#jpswin
This answer is a bit trivial but might still save time.
Check your java application is not lauched with the "-XX:-UsePerfData" option.
My username: A4000000
I had to delete C:\Users\A4000000\AppData\Local\Temp\hsperfdata_a4000000
AppData is a hidden folder.
Then once starting VisualVM again, it created the following:
C:\Users\A4000000\AppData\Local\Temp\hsperfdata_A4000000
Notice the case difference.
Then start:
C:\visualvm_213\bin> visualvm.exe --jdkhome "C:\Program Files\Java\jdk1.8.0_202" --userdir "C:\Temp\visualvm_userdir"
How do I increase the memory used by my Weblogic (Java). While starting the server from eclipse it shows a message that JAVA Memory arguments: -Xms256m -Xmx512m -XX:MaxPermSize=256m. I couldn't understand from where is it taking that value from. After sometime the Weblogic server fails because of low permgen space.
I added startup arguments from console but that doesn't have any effect. Can you help me from where is it taking the memory values from?
When you configure a "Server" in Eclipse for WebLogic, you select a domain directory (for local). That domain directory contains the startup scripts that Eclipse will use to start the WebLogic Server. These are the same scripts that you would use if you started the server if you did it without Eclipse. Inside the domain directory is a folder called "bin". In the "bin" directory, locate the setDomainEnv file (.sh for unix, or .cmd for Windows). In that file, alter the memory settings to suite your needs.
Based on the error message you mentioned in your question, I would increase both the PermSize and MaxPermSize settings to 512m. For PermSize and MaxPermSize, there are two locations each by default in a simple WLS installation, one for 32-bit, and another for 64-bit. It won't hurt to change them both. But if you know which JVM architecture you are running, you can change the one that applies to your environment.
You will have a file setDomainEnv.cmd/setDomainEnv.sh under your server bin folder. this file contains
set MEM_MAX_PERM_SIZE_64BIT=-XX:MaxPermSize=512m
set MEM_MAX_PERM_SIZE_32BIT=-XX:MaxPermSize=512m
Max and Min memory values as
if "%JAVA_VENDOR%"=="Sun" (
set WLS_MEM_ARGS_64BIT=-Xms256m -Xmx512m
set WLS_MEM_ARGS_32BIT=-Xms256m -Xmx512m
) else (
set WLS_MEM_ARGS_64BIT=-Xms512m -Xmx512m
set WLS_MEM_ARGS_32BIT=-Xms512m -Xmx512m
)
You can update the values inside it.
In addition to the previous two answers that are correct (modifying setDomainEnv and potentially wl_server\common\bin\commEnv), you can also modify servers individually if you are starting them with the nodemanager.
In the admin console navigate to:
Servers -> <server name> -> Server Start tab -> Arguments
Here you can set the JVM args you want for that server rather than making a blanket change in all servers to setDomainEnv
Looks like eclipse plugin adds it own USER_MEM_ARGS variable, so it should be rewritten using following approach:
Open following file:
$WL_HOME/user_projects/domains/mydomain/bin/setDomainEnv.sh
and add the next line to it (e.g. after help description)
USER_MEM_ARGS=$ECLIPSE_MEM_ARGS
Then, open weblogic server properties (double click at weblogic in servers view) and click "Open launch configuration". In a opened window select "Environment" and add new variable ECLIPSE_MEM_ARGS with memory params as value, e.g.:
ECLIPSE_MEM_ARGS=-Xms1024m -Xmx2048m -XX:MaxPermSize=512m
Save and check that server was applied new configuration.
P.S. Using this approach you can change/add memory params directly from eclipse.
P.S.S. In Windows you should use setDomainEnv.cmd file and added line should be:
set USER_MEM_ARGS=%ECLIPSE_MEM_ARGS%
For Weblogic12:
Environment->Servers->[your_server]->Configuration/Server Start -> Arguments:
-Xms1024m -Xmx2048m
Restart the server:
Environment->Servers->[your_server]->Control/"Start/Stop" -> Suspend and then Start.
Check your memory:
Environment->Servers->[your_server]->Monitoring/Performance.
This question already has answers here:
How to pass the -D additional parameter while starting tomcat?
(6 answers)
Closed 5 years ago.
I have a webProject with a VM Argument called "-Dfolder"
I use that argument on applicationContext like this:
<value>file:${FNET_CORE_CONFIG}/conf/${folder}/jdbc.properties</value>
In Eclipse, for testing, i use "Run Configuration" to set the value like this:
-Dfolder=Dev
Now, I want to test my webapp on Apache Tomcat so I need to set/send the folder VM Argument.
How I do that?
I have to use setenv.sh? How?. Can someone give me and example?
Thanks and sorry for my english
I don't know what version of Tomcat you using, but in Tomcat 7 in file catalina.sh you can specify variable CATALINA_OPTS and this variable will pass to jvm.
But maybe setting environment variable isn't a best way to achive your goal. Maybe best will be creation of separate "app.properties" file, and including it in applicationContext like this:
<context:property-placeholder location="classpath*:app.properties" />
And solution for catalina.sh
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.
example:
CATALINA_OPTS="-Dfolder=Dev"
EDIT:
for windows it should be something like set CATALINA_OPTS="-Dfolder=Dev"
EDIT:
In Spring configuration you can use system property just like ${propertyname}, and also can include file with property definition, with context:property-placeholder, and all defined in that file properties also become avaliable in config.
For example, you have base set properties: config.properties, and set of files with db connection settings (DEV.properties, UAT.properties, PROD.properties). So, how can you include different properties for different environment? It can be done it many ways, for example, set system properties in catalina.bat
set CATALINA_OPTS="-Dbuild=DEV"
and in applicationConfig.xml
<context:property-placeholder location="classpath*:${build}.properties, classpath*:config.properties" />
Or you can create different build configuration and include in final WAR only one properties (DEV, UAT, PROD) for each build configuration. In applicationConfig set something like:
<context:property-placeholder location="classpath*:*.properties" />
Go to $CATALINA_HOME and edit setenv.sh file by adding the parameters with the value.
If you want to mass multiple parameters, separate them using space
E.g.
cd /opt/tomcat/bin/
sudo nano setenv.sh
edit the line
CATALINA_OPTS="${CATALINA_OPTS}"
to
CATALINA_OPTS="${CATALINA_OPTS} -Dparam=value -Dparam2=value2"
restart tomcat:
service tomcat restart
you should now be able to see the arguments passed to tomcat when you run:
ps aux | grep tomcat
Made it work in Windows, by generating a setenv.bat file in the same directory as catalina.bat and startup.bat (as recommended in catalina.bat)
and put in the contents of the .bat:
set CATALINA_OPTS="-DyourVariableName=yourValue"
That's all. I liked this way as it looks pretty clean
I'm manually running tomcat 6 as a windows service on the console. I need to change java_opts before starting it. How do I do that? Also, Is there a way I can see the logs dynamically?
I know this is an old thread but needed to correct some assumptions.
Just an FYI, Catalina.bat is not utilized when running tomcat as a service. here is the method to change the JAVA_OPTS for tomcat running as a windows service.
Open Services and click on the Tomcat service. Make a note of the service name (most likely Tomcat6).
cd to the Tomcat bin directory
Run the command
tomcat6w //ES//Tomcat6 (substitute your service name if different)
Click on the Java tab
Add the options (each on a new line) to the Java Options box and set the initial and max memory to 1536 and 2048
-XX:MaxPermSize=256m
-Djava.awt.headless=true
-Djava.net.preferIPv4Stack=true
Click apply
Click on the general tab and restart the service
To change the settings, create a file named setenv.bat for windows or setenv.sh for Linux with entry as below:
Windows:
set JAVA_OPTS="-Xms256m -Xmx512m"
Linux:
export JAVA_OPTS="-Xms256m -Xmx512m"
Simply put this(setenv.bat/setenv.sh) file in %CATALINA_HOME%\bin\ folder. Your command file (catalina.bat/catalina.sh) already has a statement as below:
Windows:
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
Linux:
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
. "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
. "$CATALINA_HOME/bin/setenv.sh"
fi
This will take care the rest.
To alter the $JAVA_OPTS, you will probably need to edit the batch file you use to start Tomcat. I don't run Tomcat on Windows, but the $JAVA_OPTS appears in my catalina.sh inside the bin/ directory on my Linux installation.
As far as viewing logs dynamically on Windows, there are a couple of options I'm aware of.
Download and install Cygwin, and then on the command-line, use tail -f logfilename like you would in Linux.
Get the BearTail program and use that to follow your log files.
You can set your JAVA_OPTS environment variable either manually via the command line prior to starting Tomcat:
set JAVA_OPTS=youropts
or you can edit catalina.bat with the values you want.
In windows, cut the quotes on the set command. Quotes are taken literally.