I have imported an Existing Application into Eclipse Helios Version.
I am using Tomcat 6.0 server.
Inside our code we have this:
instanceName = System.getProperty("tata.instanceName");
systemPath = System.getProperty("tata.home");
Please tell me where should I define this properties? (SO that it reads this values from our environemnt)
For your information, I would be developing application inside the Windows and deploy it into Remote Linux server .
You can either do it as part of the java command by specifing the -Dkey=value pairs or do it programmatically.
java com.foo.Bar -Dtata.instanceName=baz
or
System.setProperty("tata.instanceName", "baz");
One option would be using -D flags when running Tomcat.
On the command line you can do
-Dtata.instanceName=name -Dtata.home=home
Add lines like this to $TOMCAT_HOME/bin/setenv.sh
export JAVA_OPTS="${JAVA_OPTS} -Dpropname=value "
in eclipse, double-click the server, "Open launch configuration", go to "Arguments" tab, and add the properies.
outside of eclipse, add them to JAVA_OPTS in catalina.bat / catalina.sh
The format of the properties is:
-Dtata.instanceName=foo -Dtata.home=bar
Related
Here's what I do in SpringBoot on Windows to read an environment variable (location of log folder).
In Windows Server, I set a System environment variable for "LOG_HOME" with the value with the directory that SpringBoot should use to write logs.
In SpringBoot's application.properties, I have:
logging.file.name= ${LOG_HOME}/ws.log
Works great!
But in Ubuntu Linux 20.04, the same approach doesn't work for me at all.
When the WAR file tries to deploy on Ubuntu 20.04 using this similar technique:
(in .bashrc): export LOG_HOME = /home/ubuntu/logs
reboot (to reload the environment for sure)
I get this error in the Tomcat log when trying to deploy the WAR file:
java.lang.IllegalArgumentException: Could not resolve placeholder 'LOG_HOME' in value "${LOG_HOME}/ws.log"
So, it seems that Spring doesn't see the environment variable set in Ubuntu.
I wrote a simple Java program just to check the value of the environment variables and they were all created as expected including the LOG_HOME as shown in Linux "printenv".
If possible, I need a technique that will work on Ubuntu without changing the working SpringBoot implementation on Windows Server.
Thanks in advance for suggestions.
Instead of exporting in shell session like
export LOG_HOME = /home/ubuntu/logs
try this as -D VM argument in your starup command
eg:
java -cp=xxx mainclass -DLOG_HOME=/home/ubuntu/log
if you are using tomcat then :
VM args can be added catalina.sh file under CATALINA_OPTS.
For tomcat, add your environment variables to $TOMCAT_HOME/bin/setenv.sh where $TOMCAT_HOME is the directory of your tomcat installation.
The solution for me posted by the extremely helpful satyesht above, was to edit the Catalina.sh file and add the "-D" name-value pair option under CATALINA_OPTS. Thanks to all who posted. :)
How to setup in IntelliJ IDEA VM options.
I need to setup
set JAVA_OPTS="-Dtomee.serialization.class.whitelist="
set CATALINA_OPTS="-Dtomee.serialization.class.blacklist=-"
In run/debug configuration for my local tomee server I pass into VM options
-tomee.serialization.class.whitelist=*
-tomee.serialization.class.blacklist=-
also tried without *.
It still giving me "invalid arguments" error after run/debug the server. How to set it properly?
ps.If I run the server manually everything works correct.
You need to specify the two properties as Java system properties (-D) in the VM options of your run configuration:
-Dtomee.serialization.class.whitelist=*
-Dtomee.serialization.class.blacklist=-
you can set them in idea.exe.vmoptions (should be in bin directory of idea installation) to force it for client side and in conf/system.properties of the tomee instance for the server.
I have a maven project, after running command mvn install all project as well as module compile and copied to local repository successfully. But now I want to run the generated web application in tomcat6. Client provided some parameter for tomcat like -Dapp.username,-Dapp.username, which will be used internally once project will start.ButI do not know how to set these additional parameter in tomcat6. Below is my development environment
OS = Windows
Tomcat = tomcat 6.0.27
Please help me?
For Tomcat 6 you should add the params to the startup.sh (Windows startup.bat). For Tomcat 7 and above you should set the parameters in the {Catalina Root}/bin/setenv.sh like such:
export CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password"
Or in Windows:
set CATALINA_OPTS="$CATALINA_OPTS -Dapp.username=username -Dapp.password=password"
NOTE: Notice the $CATALINA_OPTS at the beginning so you don't wipe out any previously set values. Not doing so can create a very hard to debug problem!
If the parameters you are setting are solely to be used by Tomcat then be sure to set it using CATALINA_OPTS.
If your application will be using the parameters then be sure to use JAVA_OPTS instead. Tomcat will also read these parameters. This can also go in the setenv.sh file. For instance:
export JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password"
Or in Windows:
set JAVA_OPTS="$JAVA_OPTS -Dapp.username=username -Dapp.password=password"
You can set an environment variable to do that. E.g. in Linux:
export JAVA_OPTS="-Dapp.username -Dapp.username"
Or in Windows:
set JAVA_OPTS="-Dapp.username -Dapp.username"
Do this before starting Tomcat
You will want to set the CATALINA_OPTS system variable - this is read by Tomcat (and only by Tomcat) when starting. As #Betoverse says you can set this using the two methods:
export CATALINA_OPTS="-Dapp.username -Dapp.username"
Or in Windows:
set CATALINA_OPTS="-Dapp.username -Dapp.username"
You can add that command to your ~/.profile on UNIX to have it set automatically.
I have tested params for Tomcat 7/8 on Windows 10 and CentOs 7 (Linux).
1) On Windows need to create setenv.bat in the {TOMCAT_HOME}/bin/ path and insert there such code:
set CATALINA_OPTS=-Dapp.username=admin -Dapp.password=12345
IMPORTANT: do not use quotes (" ") for setting params on windows.
2) On CentOs need to create setenv.sh in the {TOMCAT_HOME}/bin/ path and insert there such code:
export CATALINA_OPTS="-Dapp.username=admin -Dapp.password=12345"
You can also create {TOMCAT_HOME}/conf/conf.d/custom.conf and insert the same export command there.
If you don't want to change your environments or edit the .sh files you can start the server with something like the following
CATALINA_OPTS="-Dparam1=value1 -Dparam2=value2" catalina.sh start
before starting tomcat server right click project --> Run as --> Run Configurations
second tab --> -Dname=values , -Dname=values , -Dname=values
what about +Dname=value ,, values it become encrypted
I use JBoss 7 server so I downloaded JBoss 7.1.1 version and unzip this zip file.
Then I go to bin folder and double click on standalone.bat but new cmd window open and close within 2 -3 sec.
If I run it using cmd, I get:
E:\jboss-as-7.1.1.Final\bin>standalone.bat
Calling "E:\jboss-as-7.1.1.Final\bin\standalone.conf.bat"
then it stops.
So the JBoss server does not start.
How can I run JBoss server and deploy projects in it on Window 7?
Give JAVA_HOME environment variable in your System Properties Environment Variables likes this;
C:\Program Files\Java\jdk1.7
Give JBOSS_HOME environment variable in your System Properties Environment Variables likes this;
E:\jboss-as-7.1.1.Final
Could you try by putting your Java outside "Program Files". Sometimes commands fail because of the space in the path. Like your JAVA_HOME path is set to "C:\Program Files\Java" and hence it might be failing.
Please try to put Java folder directly under C:\ and set the JAVA_HOME variable (without bin) and also JBOSS_HOME variable in similar way (without bin).
Have you tried right clicking "cmd" and "Run as administrator"? Then cd to the folder and run it there...
or right click the bat file and "Run as administrator"?
I think usually starting server required administrator rights in Windows 7.
It solved. Changing the java_home to c:\java\jdk1.6.0_23 and setting java_home environment variable to that route
You need to add both JBOSS_HOME AND JAVA_HOME as explained above.
I have different projects using different version of JDK (5.0, 6.0) and Tomcat(6.0, 7.0), so how should my JAVA_HOME and CATALINA_HOME be set in environment variables?
Or maybe it is NOT necessary to set JAVA_HOME and CATALINA_HOME in environment variables if I am running my App by .War file? The jdk/tomcat server will be running the version I picked when I packed it (through Eclipse -> preferences...).
Inside the tomcat startup script /bin/catalina.sh, the following environmental variables are used:
JAVA_HOME is the path of JDK that used to run the tomcat and web applications
CATALINA_HOME is the path of the tomcat binaries files
CATALINA_BASE is the path the tomcat configuration files
So , how about this approach? For example :
Install JDK 5.0 to : /opt/jdk5
Install JDK 6.0 to : /opt/jdk6
Install tomcat 6.0 to :/opt/tomcat6
Install tomcat 7.0 to : /opt/tomcat7
Each of your web application has their own folder to hold their own tomcat 's configuration. For example :
/home/web1 for the web application 1
/home/web2 for the web application 2
Inside each of these folders , we need the following sub directories: conf, logs, temp, webapps, and work.Simply copy these sub directories from the tomcat installation folder (ie. /opt/tomcat7/) .Then put the .war to the corresponding webapps folders (e.g. /home/web1/webapps/webappl.war , /home/web2/webapps/webapp2.war ).
Finally , write a script to start the tomcat using different JDK and tomcat for each application . For example , to start web1, your script should look likes:
JAVA_HOME=/path/to/jdk #eg./opt/jdk6
CATALINA_HOME=/path/to/tomcat/installation #eg./opt/tomcat7
CATALINA_BASE=/home/web1/
export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE
$CATALINA_HOME/bin/catalina.sh start
Reference :
http://www.mohancheema.net/appserver/setting-tomcat-to-run-mutiple-instances-of-it
If you are running it with in Eclipse, you can use the Run Configuration dialog to set any enviornment variables that you need to change. These get automatically set when you execute the specified Run configuration. To use this, Right Click on your project, select Run -> Run Configurations. In that you can select a Run Configuration, and goto the Environment tab, and there you can specify the custom variables you want, and also you can override anything that is set by the O/S.
If you want to do this outside eclipse, and you keep a copy of Tomcat dedicated for each project, edit the startup.sh or startup.bat files depending on your OS and then set the environemnt variables explicitly there.
Ex. For Project 1:, on top of /opt/apache-tomcat6-1/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk1'
export JAVA_HOME='/opt/apache-tomcat6-1'
Ex. For Project 2:, on top of /opt/apache-tomcat6-2/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk2'
export JAVA_HOME='/opt/apache-tomcat6-2'
If you don't have a dedicated copy of Tomcat, then you can create a shell script / batch file per project which will set the necessary environment variables like this and then invoke the corresponding startup.sh or startup.bat file.
These variables are used by the scripts that start Tomcat, and don't matter otherwise. You can set them immediately before running the startup.sh script, or you can edit the catalina.sh script to set the values in the script itself (this is a good way to do it, since catalina.sh is shared by the other scripts), or you can write your own scripts which set the variables and then call the tomcat scripts... There are many possibilities. You just can't set the variables globally.