Servlet environment variables
Hi
I'm developing a webservice and I need it to read some configuration info (database related stuff mainly: database name, jdbc driver, etc). Are the environment variables definable in the web.xml file, the way to go?
And, how can I access them inside the service code?
Thanks in advance!
For smallish systems web.xml can be used. Google for "getInitParameter example", e.g. the one in javaalmanac.com seems ok.
For larger systems you may want code reuse. Then the servlets would usually be a fairly thin layer on top of "business code", database code and reusable libraries. You'll want to separate most code away from servlets so you can test (jUnit) and reuse the bulk of the code in non-servlet programs. You wouldn't want to do configuration with web.xml and getInitParameter() because those are servlet-only. You'd put configuration in a properties file and access it with java.util.Properties. Alternatively an XML solution if you have a lot of structured configuration.
You could go Properties right away, it's a few lines more code depending on how you do it. Google "java properties example", starting with javaalmanac.com.
If your service is to be installed in an existing environment, ask the sysadmins what existing code does and what they prefer. They are the customers of your config mechanism.
Similar Messages
-
Servlets: how do I get client's environment variables
Hi everybody
I make various servlets, and like to get the client's environment variables (such as used by the SET command under Windows). Especially username which is set in Windows-NT.
Are there any straight forward way to get these?
.. or can I get them and return them via a javaScript?
ArneThe servlet runs on the server. The browser and JavaScript run on the client. If you wanted to use JavaScript to pass them back, you would have to pass them back to the server through another servlet.
Or you could use an applet and get at the standard Java properties. Nobody should use environment variables anyway, as you can't guarantee a computer even has them. :-) -
From Where should i download Servlets and how to set Environment variables?
Hi,
I want to download the Servlets Kit for my development of application,but couldnt find it.I found a zip file containing all class files.If that is the correct one,then how should i set my environment variables?
thanks
raoYour files should come in a folder with the name "Javax" and subfolders right?
What you can do is to paste the file "Javax" in your folder of your JDK installation.
For example, I have installed my JDK in C:\Java\jdk1.3
I added one new folder in C:\Java\jdk1.3 called classes.
Then I would put the Javax folder in classes.
PS : We add one new folder called classes so that in future when you want to add new classes you can just into this folder.
Then in your enviroment settings, simple point to C:\Java\jdk1.3\classes;.;
This works for me. Hopefully you will no problems!
jing
170902 -
Error in setting environment variable
hi
Please note JKit is where my jdk1.3 is stored(i.e instead of jdk1.3 folder its JKit folder)... i have gone thru the similar threads but with no success.
SET
PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;D:\Jkit\bin;D:\Jkit\lib;D:\Oracle\bin;"C:\PROGRAMFILES\ORACLE\JRE\1.1.7\BIN";D:\JKit\Jre\Bin;
SET PATH=%PATH%;C:\PROGRA~1\COMMON~1\AUTODE~1;
SET CLASSPATH=c:\JavaWebServer2.0\lib\servlet.jar;c:\JKit\lib;
SET CATALINA_HOME=D:\tomcat\jakarta-tomcat-4.1.29;
SET JAVA_HOME=D:\Jkit;
The error i get after running autoexec.bat and then tomcat/bin/startup is as follows..
The CATALINA_HOME environment variable is not defined
This environment variable is needed to run this program
please HELP!!.THANKSHi
Very many thanks for ur solution.. i actually hadset the environment variables spacce..but when i execute the autoexec.bat file i dont get any error(out of env space)..but when i run the startup.bat file i get from the command prompt, i get the foll error.
This is my Autoexec.bat
SET JAVA_HOME=D:\Jkit\bin
SET CATALINA_HOME=D:\tomcat\jakarta-tomcat-4.1.29\bin
SET PATH=D:\Jkit\bin;C:\WINDOWS;C:\WINDOWS\COMMAND;
SET PATH=%PATH%;C:\PROGRA~1\COMMON~1\AUTODE~1;
THE FOLLOWING IS THE ERROR I GET WHEN I RUN STARTUP.BAT UNDER TOMCAT'S BIN UNDER THE COMMAND PROMPT
D:\tomcat\jakarta-tomcat-4.1.29\bin>startup
Syntax error
Out of environment space
Out of environment space
Out of environment space
Using CATALINA_BASE: D:\tomcat\jakarta-tomcat-4.1.29
Using CATALINA_HOME: D:\tomcat\jakarta-tomcat-4.1.29
Using CATALINA_TMPDIR: D:\tomcat\jakarta-tomcat-4.1.29\temp
Using JAVA_HOME: D:\Jkit
Out of environment space
Out of environment space
Invalid switch - -DJAVA.ENDORSED.DIRS=D:\TOMCAT\JAKARTA-TOMCAT-4.1.29\COMMON\ENDORSED
I even set JAVA_HOME AND CATALINE_HOME to the \bin dir respectively..
still i get the same error
As given under the tomcat installation documentation (RUNNING.txt), i set the space for environment space under the Memory tab, for startup and shutdown.bat files, it creates a shortcut for running the resp .bat files, running startup.bat file i get,CATALINA_HOME VAR HAS NOT BEEN SET PROPERLY, THIS OCCURS FOR BOTH TOP LEVEL DIR SETTING AND /bin DIR SETTING of CATALINE_HOME IN autoexec.bat
PLEASE HEL, I HAVE BEEN TRYING TO CONFIGURE IT FOR THE PAST DAYS BUT WITH NO SUCCESS, DONT KNOW WHERE I AM GOING WRONG..PLEASE HELP -
Setting Environment Variable CPIC_MAX_CONV
Hi Experts,
In of the steps during POST INSTALLATION of PI7.0 it says to set the variable CPIC_MAX_CONV, using the transaction RZ10.
When i logged in to the abap system , and checked in RZ10,did find any variable of this name.
Do I need to create it first and then set the value gw/max_conn_per_wp.
If yes, give me the steps to do this. or else any other alternative.
Thanks in advance,
YounusHi,
Check this note :
1.- https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_fes/~form/handler%7b5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d333136383737%7d
2.- /thread/174978
The parameter CPIC_MAX_CONV is a environment variable that you find in Unix or windows, depends where you had installed SAP PI.
Best regards
Ivá -
Library paths and environment variables
Hello,
I am using 10g AS 9.0.4 on a Unix system.
I am trying to convert an old JSP web application to work with 10g. It is not an EAR/WAR file so I am manually trying to set it up under the "default-web-app" folder. It uses a number of java class files which currently reside in $J2EE_HOME/default-web-app/WEB-INF/classes/mystuff.
These class files require access to a number of libraries. I foolishly believed that they would be accessible if I were to place them in the $J2EE_HOME/default-web-app/WEB-INF/lib folder, but that did not work.
I read that OC4J uses a "catch all" lib directory at $J2EE_HOME/applib. I copied the library files there and they still did not work.
Frustrated, I tried to print out the environment variables for the server - only to find that this function is not supported.
I managed to print out the library path by creating a Java class files which returns the following as a string:
System.getProperty("java.library.path");
This (when called from a JSP) prints a number of different library paths, none of which match those found listed in the $J2EE_HOME/config/application.xml file. I placed the library files in one of the paths listed by the "java.library.path" and it worked!
3 questions:
1. How do you print the server's environment variables using a JSP? This strikes me as a very useful function for sorting out library and path issues. Do a search on Google for "print environment variables OC4J" or something similar and there are no useful pages suggesting how this can be done.
2. Why are the default library paths different on the server than to those specified in application.xml?
3. How do I change the LD_LIBRARY_PATH (or any environment variable for that matter)? I have tried adding the following line to $ORACLE_HOME/Apache/Jserv/etc/jserv.properties without success:
wrapper.env=LD_LIBRARY_PATH=/my/custom/library/path
Any help you can offer would be most appreciated.>
Thanks very much for a such a comprehensive response
- it has helped answer a lot of questions, especially
being able to print out the system properties. That
will be really useful!
No worries at all Rob.
The main hurdle is that the libraries are indeed
native (*.so) libraries. I hadn't considered that
until you pointed it out in your message. Can I
assume, then, that $J2EE_HOME/applib and
$J2EE_HOME/default-web-app/WEB-INF/lib are only
designed to handle Java's .JAR librares? That would
explain why placing the native libraries in there
didn't work, but is there a way of getting such
native libraries recognised and bundled up in a
WAR/EAR file?
Yep, that's it.
Our proprietary applib and the servlet specs web-inf/lib are only dealing with Java archives.
The J2EE specs don't cover how to deal with native libs like this.
Now I've NEVER EVER tried it, but it's worth a shot of at least trying -- for simplified packaging purposes, what you may be able to do is to distribute the .so's within the web-inf/lib -- and then just set that directory (where's its realized on the server after the app is deployed) to be referenced witihn the LD_LIBRARY_PATH. I'd expect our deployment manager will just ignore files it doesn't know about, so arguably you should be able to at least distribute them with the standard archive.
You'll need to specifically set the LD_LIBRARY_PATH as a separate task outside of the deployment operation though.
>
This is where things get a bit weird, and is partly
my fault during the installation of 10g AS.
We already had an existing installation of Oracle 10g
Database (10.1.0) at $ORACLE_HOME under the user
"oracle". I logged in as the user "oracle" to install
the Application Server into a different location (In
this case, "$ORACLE_HOME/../ias10g_9.0.4" - let's
call this $IAS_HOME). So there is no separate user
account for Oracle Database and Application Server
(and hence no separate $LD_LIBRARY_PATH).
If I log into UNIX as the user "oracle" and echo the
LD_LIBRARY_PATH, I get the following directories:
$ORACLE_HOME/lib
/usr/openv/netbackup/bin
/usr/dt/lib
/usr/lib
I use this user to do "opmnctl stopall" and "opmnctl
startall". If I then print out the library path from
a JSP using
"System.getProperty("java.library.path");", I get the
following paths:
$IAS_HOME/jdk/jre/lib/sparc/server
$IAS_HOME/jdk/jre/lib/sparc
$IAS_HOME/jdk/jre/../lib/sparc
$IAS_HOME/opmn/lib
$IAS_HOME/lib
$IAS_HOME/usr/lib
Which is totally different to those listed by
$LD_LIBRARY_PATH at the command line, which means
they must be coming from somewhere else.
It gets worse - my application is trying to call a
native library that is only present in the
$ORACLE_HOME/lib32 directory (libclntsh.so.10.1), so
unless I can include this path in the
"java.library.path" on the Applicaiton Server, then
my program will not work.
So, how do I change the "java.library.path" when the
values aren't coming from $LD_LIBRARY_PATH in the
first place?
The utility $IAS_HOME/opmn/bin/opmnctl is actually a shell script.
It has this section which sets the LD_LIBRARY_PATH:
if [ -z "$LD_LIBRARY_PATH" ]
then
LD_LIBRARY_PATH=$ORACLE_HOME/opmn/lib:$ORACLE_HOME/lib ; export LD_LIBRARY_PATH
else LD_LIBRARY_PATH=$ORACLE_HOME/opmn/lib:$ORACLE_HOME/lib:${LD_LIBRARY_PATH} ; export LD_LIBRARY_PATH
fi
So if you have an existing LD_LIBRARY_PATH env var set, it should just be putting its paths onto the front of it.
What you could try as a quick test is to edit the opmnctl script (after taking a backup of course) and either appending the path you need to it, or just add some debug statements to output the LD_LIBRARY_PATH value it ends up setting so you can try and work out what's causing it.
I expect these other entries:
$IAS_HOME/jdk/jre/lib/sparc/server
$IAS_HOME/jdk/jre/lib/sparc
$IAS_HOME/jdk/jre/../lib/sparc
are coming from the JRE when it is launched, in probably a similar manner to our opmn entries.
I really appreciate your help, and I bet if anyone
can answer these questions, you can! ;-)
You're very welcome.
cheers
-steve- -
How to set new Tomcat Environment variable?
I have an imported class used by my servlet that is supposed to look for an environment variable like "xxx.app.logdir". I'm having trouble setting it in Tomcat. I have tried the following (stopping and starting Tomcat with each change):
1) In \conf\server.xml file, adding under <GlobalNamingResources> <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Environment name="xxx.app.logdir" type="java.lang.String" value="C:\\Tomcat-4-1\\logs"/>2) In my app's web.xml file <env-entry>
<env-entry-name>xxx.app.logdir</env-entry-name>
<env-entry-value>C:\\Tomcat-4-1\\logs</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry> 3) In my \bin\startup.bat file
set xxx.app.logdir=C:\\Tomcat-4-1\\
4) On my PC's Environment variables.
Nothing has worked. In my code I have the lines
logMsg("System.getProperty('mmm.app.logdir')=" +
System.getProperty("xxx.app.logdir"));
logMsg("System.getProperty('simpleValue')=" +
System.getProperty("simpleValue")); with the output :System.getProperty('xxx.app.logdir')=null
System.getProperty('simpleValue')=null I've searched forums and the Tomcat docs, but no luck. Any ideas?I tried that as well, but maybe I didn't define my DefaultContect correctly. Do I need any other parameters? Couldn't find it in the Tomcat docs. <DefaultContext>
<Environment name="matt" type="java.lang.String" value="value1" />
</DefaultContext>My new code (I simplified the variable name for testing):
System.out.println("System.getProperty('matt')=" + System.getProperty("matt"));
System.out.println("System.getProperty('MATT')=" + System.getProperty("MATT"));Results:
System.getProperty('matt')=null
System.getProperty('MATT')=null -
Setup JAVA_HOME n CATALINA_HOME environment variable
Hi there
im new in Java Servlet programming... im confused how to setup JAVA_HOME n CATALINA_HOME environment variable... if any1 of u know this plz help me to how to setup it... it will help me very much.
thanks in advance
112Once you have identified the JDK install path:
1. Right click on the My Computer icon on your desktop and select properties
2. Click the Advanced Tab
3. Click the Environment Variables button
4. Click New
5. Enter the variable name as JAVA_HOME
6. Enter the variable value as the install path for the Java Development Kit.
7. OK
Next you have set an environment variable CATALINA_HOME that contains the pathname to the directory in which Tomcat 5 has been installed, the same way you set the JAVA_HOME ev. -
Environment variables like classpath,JAVA_HOME,path
Sir,
I work as a java developer in a software company.I had more problems when executing servlets."could not create the java vitual machine" error comes when i try to compile java servlet file.also I do not know that how to set environment variables like classpath,path and JAVA_HOME.Also I want to know them with proper examples.
Thanking you.
KRameshHi Teches
I am facing few problem in starting eclipse 3.0 ; I had gone trogh forum , 1 of the persone suggest me to upgrade the java version.For this
I had installed java 1.5 and set the following variable
JAVA_HOME ---> to the home dir of JAVA
PATH ---><home dir>/bin
CLASSPATH --><jre>/lib
But when ever i m giving "java -version" command on console , the result is as follows:
C:\>java -version
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
suggestion are welcome Plz.
; -
Classpath in Environment Variables
Dear All,
After I put " ; " in front of Environment Variables in Win XP System Properties
so my classpath=;C:\tomcat4\common\lib\servlet.jar;C:\tomcat4\webapps\aplikasiku\WEB-INF\lib\mssqlserver.jar;C:\tomcat4\webapps\aplikasiku\WEB-INF\lib\msbase.jar;C:\tomcat4\webapps\aplikasiku\WEB-INF\lib\msutil.jar. then my problem solved. I never found NoClassDefFoundError in my java.
Is it ok to use that classpath?
ThanksHi,
It can be used but should really really be avoided since it makes it makes it very hard to use when you have multiple applications, and applications of different versions.
Kaj -
Setting Linux environment variable
Is there other web site which talks about how to set the environment variable of J2EE for Linux?
I followed this web site
http://www.dougsparling.com/comp/howto/linux_java.html
but after all
when I tired to compile a servlet program... it couldn't be complied. I think the case is that the compiler couldn't find servlet.jar ...
why is that?You have to verify that your CLASSPATH environment variable is set in your account's profile. I use the
bash shell therefore my variables are set in .bashrc
for example my CLASSPATH is set to :
CLASSPATH=.:$J2EE_HOME/lib/j2ee.jar:$J2EE_HOME/lib/locale -
Settting environment variables
Oracle 9i AS on HP_UX.
From within the servlet application I use Runtime.Exec() to start another process but it doesn't have access to the environment variables it needs, e.g. LD_LIBARY_PATH, even though these have been set in .profile.
I have also tried adding them to jserv.properties, but still no result.
Can anyone explain how to make environment variables available within the servlet application
Thanks
DaveYes it shows up after restart of BIDS .
But during design time this is a bug I hope Microsoft fixes this bug in the future releases
Mudassar
It's not really a bug. Visual Studio loads the environment variables when starting up.
In future releases you use projects and parameters instead of environment variables, so the issue goes away ;)
MCSE SQL Server 2012 - Please mark posts as answered where appropriate. -
Get environment variable from servelet
hello
in my servlet,there is following code block:
File f=new File("%JAVA_HOME%\\test.txt");
f.createNewFile();
the "JAVA_HOME" is the environment variable of my windows.after i deploy it to jboss,it threw exception.that tell me can't find the path.
then i modify it as:
File f=new File("%JBOSS_HOME%\\test.txt");
f.createNewFile();
the "JBOSS_HOME" is definde in its "run.bat " file.
the code still don't work.
who can tell me :
1 how can i use the environment variable of os or app server?
2 how and where can i set up a envrionment variable as the base dir ?
thank you.This is a bad idea.
You shouldn't use absolute file paths or the java.io.File class for that matter in Web apps.
Better to look in the servlet context using getResourceAsStream(). That'll return an InputStream that you'll be able to read to your heart's content. -
Once again oci8 on AIX: environment variables
Hallo,
I don't know how I have to set my environment variables, when I
use the oci8 on AIX. Is there someone who could tell me this?
Thanks
J. Ohngemach
nullhi,
take a look :
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a245e690-0201-0010-4393-ef078d3ad0ed
https://service.sap.com/instguides
SAP NetWeaver->Installation->SAP BW -
hi. i have jboss 3.2.2 aplication server with tomcat 4 embedded on mac server 10.4.11. The problem is the java_home variable...i need set up java_home for current jdk (1.5). I have changed the profile archive in /etc and created other archive .profile in my directory home. this way:
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
export JAVA_HOME
but..not work! in the Jboss's parameters is still java_home pointing to jdk 1.4.
1. sorry for my english..(i hope you understand).
2. where should I set environment variables?
3. How to set up jboss 3.2.2 only for jsp's with tomcat 4 enmbeded?
thanks. JonathanHi,
Sorry to post this...it doesn't have anything to do
with Java programming. But I about to pull my hair
out!
Trying to run Jboss. Had it up and running then I
added some environment variables to my
classpath...which caused JBoss to stop running do I
removed the variables and Jboss still wont run:
this is the error message I get:
C:\j2ee\jboss\bin>run
Could not locate
C:\JDK\BIN;C:\SSH;C:\JDK\lib\tools.jar. Unexpected
results may
occur.
Make sure that JAVA_HOME points to a JDK and not a
JRE.
Syntax error
I cant figure out what is causing this? Any ideas
would be greatly appreciated.
thank you
The answer is in the error message. You need to set JAVA_HOME, and that it points to a JDK not a JRE, because JBoss uses JSPs, which get compiled to servlets, which means it needs to find the java compiler classes, which are found at JAVA_HOME for a JDK. Phew. I guess the unexpected results they're hinting at are that your JSPs ( and probably some other things ) will just not work.
Maybe you are looking for
-
Multiple Feedback Messages in Quiz Results
Hello Everyone, I am sure I have seen the answer here somewhere, but I cannot find it now. So, here is my situation.... I am using Captivate 5.5 I have a 30 question quiz that covers 5 different topics. I want the results page to give feedback speci
-
Blink Code after System Update
Hi, after Updating my Z10 to the latest Software Release the device doesn´t boot any more. After turning on the device, the LED just have a blink code 1101111 - nothing more! I have already unplugged the accu. Any Ideas?
-
The muisc I have in my i-Touch does not match up with the music list in my Mac, therefore have issues syncing. Is there anyway to keep all those songs without losing some of it?
-
IP: Use of input-ready variable in planning function
Dear all, I'm using an input-ready variable for fiscal year (0P_FYEAR) in my input ready query. It's used for restricting my columns. I'd like to use the value of this variable in my planning function and I use VARV for that in the FOX. However, when
-
Oracle 10gR2 installation on Redhat 5 hangs on 12%
Dear experts I'm installing a 2 node Oracle 10gR2 on Redhat 5. Everything is ok when installing Oracle Clusterware and it works fine with all the services up and running. But when I start installing the Oracle Database, OUI hangs on 12%. I found coup