How to add environment variables to Tomcat 7 GUI service for windows - ruby-on-rails-3

We've successfully setup tomcat 7 for windows and jruby but now we need to set an environment variables(RAILS_ENV and some other variable) before starting Tomcat.
We start Tomcat using the GUI on the lower right, and I was wondering how to add the variables in that gui. As usual windows isn't helpful enough with the vague terms for startup like:
class, method, arguments(has the value "start"), timeout and mode(has value "jvm")
So where do I add my environment variable here? I am guessing in arguments separated by a space? Or something else?

On Windows you can add environment variables under
Control Panel -> System -> Advanced -> Environment variables (the button at the bottom)
Then you can add a variable like JRUBY_OPTS with value --1.9

Related

Mulesoft ESB Environment Variable per Project

I'm starting two Mule projects from studio. How can I set different environment variables for each project inside this one app?
If I have an application run configuration called RunBothProjects and that launches two projects: hellomule and hellomule8082.
For hellomule I want to add either an argument or environment variable that says MULE_APP=AppOne and for hellomule8082 I want to add MULE_APP=AppTwo.
Is this possible?
No, it is not possible to have separate environment variables because both Mule applications are deployed to the same Mule server. Environment variables are global per server.

Mule startup order for applications

So, i have three mule applications where one needs to be started before the other two. And I start mule as a windows service. I found this site and follow the example by putting
wrapper.app.parameter.1=-app
wrapper.app.parameter.2=%MULE_STARTUP_ORDER%
in wrapper.conf. where MULE_STARTUP_ORDER is an system variable containing App1:App2:App3
But when i look in my mule.log after staring the service app2 starts first followed by app3 and app1 is last.
And I use mule standalone 3.7.0.
Anyone have any idea what I am doing wrong/missing?
Try setting the list of applications directly in wrapper.conf in case the service has no access to the system environment variable from Windows. Also try using higher numbers for the parameters like the example in the KB article you referenced. Low numbers might be get overridden by other parameters.
Example:
wrapper.app.parameter.10=-app
wrapper.app.parameter.20=app1:app2:app3

How to set Tomcat.runtime.environment.version as PROD on the web server?

I want to set Tomcat environment variable as PROD. I tried by putting
set "ENVIRONMENT=PROD"
set JAVA_OPTS="-Dtomcat.runtime.environment.version=PROD"
in catalina.bat
and tried to retrieve it with
env = System.getProperty("tomcat.runtime.environment.version");
but every time env is null! Where exactly does the variable have to be declared in catalina.bat and what's the perfect syntax to set the environment variable? Other possible ways to declare variables are also welcome!
Since you are on Windows and in production, I'm going to assume that you are using a Microsoft Windows Service for Tomcat. If that's the case, the .bat files are completely ignored when launching and stopping Tomcat. There is a service binary that reads the configuration from the Windows Registry and no disk-based scripts are used at all.
If you run the program called tomcatXw.exe (where X is your Tomcat major version number), that will run the configuration GUI. From there, you can configure everything stored in the Registry.
Go to the "System Properties" tab and add your system property -Dtomcat.runtime.environment.version=PROD to the list of properties already found in there. Restart your service and you should be able to see the new system property available to your application (actually the whole JVM, of course).

how to add db directory to web.xml

I have a java web app configured with apache v9.0 and eclipse IDE. What I need is to keep my database in C:\db so It cannot be access directly from outside and should be away from my webapp project directory. What I don't is how to let my web app know that if a user request for a file it should go and check it in my C:\db and reply back with the file.
Based in my research, some was saying to specify my directory in my webapp web.xml file and others was saying I need to specify it in my tomcat/conf/server.xml file.
I'd really appreciate if somebody tell me what to do?
Try adding your database path C:\db as JVM argument and accessing it in application. you may try this as two ways either set as system property and access when it required or set as JVM argument and access it.
SetSystemProperties
System.setProperty("database", "C:\\db");
.
.
access it as and when required
String databasepath= System.getProperty("database");
Setting as JVM Arguments.
Double Click on your tomcat server on which your web application is present.
Click on "Open launch configuration" link and go to Arguments Tab.
in vmArguments apend the entry like below.
-Ddatabase="C:\db"
A -D is placed in front of each system property that we are passing in as a VM argument, and following this is an equal sign followed by the value of that system property.
And access it in your project where its required like below.
String databasepath= System.getProperty("database");

Artifactory not using specified home directory

I'm currently hosting Artifactory on Tomcat8/JDK1.8.
If I check the system info screen, I can see that files are being written in /u01/usr/share/tomcat8/.artifactory/
However, in the servlet configuration in bin/setenv.sh, I specified the Artifactory home to be somewhere else:
-DARTIFACTORY_HOME=/u01/opt/artifactory
Then, I discovered in the docs, it's supposed to be lower case:
-Dartifactory_home=/u01/opt/artifactory
I rebooted Tomcat after the changes and the path targetted is still /u01/usr/share/tomcat8/.artifactory. The folder is owned by the user running Tomcat as well.
Why isn't it using the specified home dir?
This seems a bit old but for others that struggle with it, you need to set an Environment variable ARTIFACTORY_HOME in your Tomcat startup script not a System variable via -D parameter.
Linux
set ARTIFACTORY_HOME=/pathto/your/artifactory
Windows
"set ARTIFACTORY_HOME=C:\path to your/artifactory"
Notice the quotes for Windows
System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System.setProperty(String key, String value) or via the various System.getProperties().load() methods.
To get a specific system property you can use System.getProperty(String key) or System.getProperty(String key, String def).
Environment variables are set in the OS, e.g. in Linux export HOME=/Users/myusername or on Windows SET WINDIR=C:\Windows etc, and, unlike properties, may not be set at runtime.
To get a specific environment variable you can use System.getenv(String name).