I need to access a variable created in a shell script from a java servlet.
After reading the related posts in this forum I still haven't figured it out.
If I export a variable on my debian system (export var=foo123) and then I want to use
this variable in my sevlet (System.getenv(var)) it always returns a null value.
I have already tried adding 'export var=foo123' in /etc/init.d/tomcat7 but to no succes.
I think that you don't need to use export, it should be enough to put:
VARIABLE_NAME="variable_value"
in tomcat script file. And don't forget the ""!
Related
So basically i have a project with a lot of packages and the corresponding jars.
im trying to run the program and to do so i need to set my CLASSPATH the thing is when im trying to set it it says command not found for some reason.
What i did was:
martim#localhost:~/project/woo-app>CLASSPATH = /usr/share/java/po-uulib.jar:/home/martimc/project/woo-app/:/home/martimc/project/woo-app/
Bash : CLASSPATH: command not found
I dont understand why this is happening
Setting environment variables in bash requires no spaces before or after the =. Furthermore, you'd have to put export in front or it won't actually provide that var to java. Lastly, don't use CLASSPATH at all; java can run many apps, apps need different classpath, so the concept of a global classpath makes no sense. Just use the -cp parameter.
PROBLEM: Hello everyone! I have created a Maven project in which i am building
a RESTful API, now i have created few .json files in which i want
to store my JSON data in src/main/resources , but as i can see
every time i make a change ( example: register a user - write in a
file ) all changes get lost whenever i redeploy the WAR file or the
server gets restarted/reloaded.
Can someone please tell me how to use system PATH variable to fix
my problem? I want to store files somewhere i will be able to update
them without having to worry if server is being reloaded or not. Thank you in advance!
SMART WAY, with java configuration and classpath (unix example, launch your application this way)
java -classpath $PATH <your-class-name>
or
setenv CLASSPATH = $PATH
see unix and windows instructions.
BAD WAY, within application code
You can read the PATH variable from the OS environment calling System.getenv() and then looking for the "PATH" elements within the returned map.
Then you have to parse the string (e.g. with StringTokenizer) obtained to get each folder within the PATH variable
you have to look for your JSON files in each of the folder from previous point
I have two instances of tomcat that run under the same user in a test/dev environment. In each instance there is an application that writes configuration data to the same directory in the $home of the user that runs tomcat.
I'd like to set one instance of tomcat so that it thinks $home is somewhere else. Is this possible? If I do export home=foo/bar when I run one instance, will that affect the other instance?
Obviously I know that I can run each instance as a different user, I do not want to do that in this case.
Just create a file "setenv.sh" for both instances
{TOMCAT1_BASE_DIR}/bin/setenv.sh:
export home=/foo/bar1
{TOMCAT2_BASE_DIR}/bin/setenv.sh:
export home=/foo/bar2
On startup tomcat will load environment variables defined in setenv.sh
You can overwrite a variable for a specified command without exporting it this way:
HOME=/home/user command.sh
The HOME variable will be changed for command.sh but will still be your usual home everywhere else.
Edit {TOMCAT_INSTANCE}/bin/setenv.sh to set all required environment variables per instance.
When I run the following command:
bin/tdbloader2 --loc=/store/data/here /seed/data/serverfault-dump.nt
And the response I get is:
10:52:31 -- TDB Bulk Loader Start
10:52:31 Data phase
Error: Could not find or load main class com.hp.hpl.jena.tdb.store.bulkloader2.CmdNodeTableBuilder
Which is most likely caused by a problem with my environment variables, somewhere, of something. The problem is, I don't often work with Java and so I don't know enough to know how to figure out what that class cannot be found.
How do make tdbloader2 find the appropriate class?
I had forgotten to set the JENAROOT path variable.
https://jena.apache.org/documentation/tools/
An environment variable JENAROOT is used by all the command line tools to
configure the class path automatically for you. You can set this up as follows:
On Linux / Mac
export JENAROOT=the directory you downloaded Jena to export
PATH=$PATH:$JENAROOT/bin On Windows
SET JENAROOT=the directory you downloaded Jena to SET
PATH=%PATH%;%JENAROOT%\bat
At a minimum you need to set the TDBROOT environment variable to the directory containing your TDB download. This will be the directory above bin as some of the scripts use ${TDBROOT}/bin/foo to launch other scripts
The script attempts to automatically construct a valid class path by calling the tdb_path script which calls either make_classpath_mvn or make_classpath depending on your environment. If you run the tdb_path script directly you can see if it generates a sane looking class path or not (or add what it does generate to your question if the output doesn't provide anything helpful).
I am running a Java application from the command line. Can I specify a command line argument to set the current running directory to something other than where the application is actually going to run?
There is a JVM argument -Duser.dir which can be used to set working directory for JVM.
If it all possible I would rather use a script to run the java application and set the directory in the script:
#!/bin/sh
cd <your dir>
java <some arguments>
The JNI-solution may affect all kinds of relative paths in your application; for examples the classpath you put in.
If you want to change the current directory, you'll have to use JNI and invoke a native API from your Java code. For example, for Windows you would use SetCurrentDirectory
I found this SO post and it helped me solve my problem. Though I wanted to share something specific about IntelliJ that might trip somebody else up.
I have posted a picture below where the -Duser.dir flag is used and also the Working Directory text field is filled in.
In this situation, the Working Directory will be set to "JarLearning" rather than "2ndTry".