I'm new to Tomcat. their is something wrong about Tomcat 7 on my ubuntu 10.10.
when I start Tomcat like this
llchli#llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ ./catalina.sh run
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.47
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.47/temp
Using JRE_HOME: /usr/local/jdk1.7.0_45
Using CLASSPATH: /usr/local/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.47/bin/tomcat-juli.jar
although cannot start Tomcat this way, it echos Using JRE_Home /usr/local/jdk1.7.0_45, which is the correct JAVA_HOME or JRE_HOME on my computer.
but when I start Tomcat with sudo like this
llchli#llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo ./catalina.sh start
[sudo] password for llchli:
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.47
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.47/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.47/bin/tomcat-juli.jar
it echos Using JRE_HOME: /usr,which is not the correct JAVA_HOME or JRE_HOME on my computer. But it start Tomcat correctly.
my /etc/environment is
llchli#llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/jdk1.7.0_45/bin"
LANGUAGE="en"
JAVA_HOME="/usr/local/jdk1.7.0_45"
CLASSPATH="$CLASSPATH:$JAVA_HOME/lib"
CATALINA_HOME="/usr/local/apache-tomcat-7.0.47"
I'm a bit puzzled about this.And when I use daemon.sh like this, it generate errors.
llchli#llchli-virtual-machine:/usr/local/apache-tomcat-7.0.47/bin$ sudo ./daemon.sh run
Cannot find any VM in Java Home /usr
Cannot find any VM in Java Home /usr
Cannot locate JVM library file
Service exit with a return value of 1
It echos cannot find any VM in Java Home /usr. I'm so confused.
Any helps and advise will appreciate.
Thanks in advance.
It sounds like "sudo" is not passing your JAVA_HOME and JAVA_PATH through to the child process.
When you run a command using "sudo" the environment variables are set according to what the sudoers file says. My reading of the "sudoers" manual entry is that the default is to NOT pass variables through. But according to the "sudo" manual entry, there is a command syntax variation that allows you to pass environment variables using "VAR=value" ...
I suggest that you read the manual entries for "sudo" and "sudoers" carefully, and then read your system's "/etc/sudoers" file to understand how it is behaving.
Having said that, launching services from the command line using "sudo" is not a good idea, especially if you are talking about "production" services. And you are generally better off using the service wrappers provided by your distro's packaging, rather than a non-packaged install from the "upstream" project.
Sudo resets the environment variables. When you run sudo, JRE_HOME is reset to its default (probably null) and Tomcat will assume its own default (/usr). You can run sudo with the -E switch to preserve the environment.
Are you sure, you must run the script as root? I have no idea how to set up Tomcat, but it is usually a good practice to run servers as a dedicated user instead of as root.
As i already state in a comment, i strongly suggest you to use the package system to install software, it it's available in the repository. (plus there are ppa's for nearly everything). That way you will keep your system tidy and you won't have worry about things not working (usually).
My suggestion is to remove your current manual install and install the tomcat7 package.
apt-get install tomcat7
For further configuration, use the file /etc/default/tomcat7. To start/stop/restart use the command service tomcat7 {start|stop|restart}.
Using the package tomcat7 the tomcat instance will run as it's own user, and not as root, and that's good, since a service should not run as a user with full privileges.
I am aware that i am actually not answering your question with the environment variables. But using the suggested way, you will not face that problem to begin with.
it is all said, it means adding to /etc/sudoers a line with:
Defaults env_keep += "JAVA_HOME JRE_HOME"
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. :)
When running the Scala interpreter in Ubuntu 14.04, I get the following message printed as the first line:
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Followed by the familiar "Welcome to Scala" message.
I'm worried because I haven't seen that when running Scala before - what does it mean, is it dangerous, etc?
Apparently the environment variable $JAVA_TOOL_OPTIONS is set to -javaagent:/usr/share/java/jayatanaag.jar - I didn't set that, but what did and why? Can I safely unset it?
Additional info:
recently installed Android Studio
The word "ayatana" in the JAR's name might point to Ubuntu's project Ayatana
You can disable jayatana just for the current shell session by unsetting JAVA_TOOL_OPTIONS like so:
unset JAVA_TOOL_OPTIONS
That way it will still be enabled for applications needing it.
This occurs if you have installed jayatana which allows the hidden global menu in eclipse to work with Unity:
sudo add-apt-repository ppa:danjaredg/jayatana
sudo apt-get update
sudo apt-get install jayatana
that puts JARs in the /usr/share/java/ folder which is echoed by the JVM when starting up.
If you remove that software, you will not see the message:
sudo apt-get remove jayatana
You may have to delete:
/usr/share/upstart/sessions/jayatana.conf
and restart your session so that the environment variable JAVA_TOOL_OPTIONS is not set.
This is because of Jayatana, which is added to Ubuntu 15.04 in order to enable global menu for Java Swing applications. You can safely remove this message by entering the following command in a terminal. This command will remove the auto-start configuration of Jayatana.
sudo rm /usr/share/upstart/sessions/jayatana.conf
However, removing this option will disable the global menu support of Java Swing applications like Netbeans, IntelliJ IDEA. I have shared my workaround to suppress the message without losing the global menu in this article: Global Menu Support for Java Applications
On Windows,
set JAVA_TOOL_OPTIONS=
Setting to null will remove it from the environment.
If you are using Windows OS, goto environment variables and delete or set to null the varible JAVA_TOOL_OPTIONS.
For those who are dealing with this error working with Groovy scripts, and working with another console (such as Git Bash), change the variable name JAVA_TOOL_OPTIONS for JAVA_OPTS
If you don't want to uninstall anything you can create a key store from a terminal:
keytool -keystore clientkeystore -genkey -alias anyalias
(you should create it at project's forlder)
And then in Android Studio click Build->Generate Signed APK and choose created keystore.
I am a newbie to Ubuntu 12.10 and moved to it from Windows.
In Windows I have configured the environment variable to include servlet-api.jar in the CLASSPATH variable so I do not have to type -cp <path to servlet-api.jar> every time I compile.
For normal Java programs, I have set the JAVA_HOME using:
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386" >> ~/.bashrc
With that solved, I need to set the CLASSPATH but do not know how to.
Please help on that!
Also I read on some forums that I should change the CLASSPATH manually each time I compile because changing the CLASSPATH may upset other applications.
Next, I tried this command to start Tomcat
service tomcat7 start but I got an error :
You need root privileges to run this script I do not know why. Help me solve that!
And if within the scope, please tell me how the directory structure of tomcat in Windows differs from that in Ubuntu.
Misc
I used sudo apt-get install tomcat7 to get Tomcat 7.
You don't say whether you're using an Ubuntu Tomcat package or a standalone Tomcat installation.
For a standalone Tomcat, you will be starting and stopping it using the scripts in its bin directory: startup.sh and shutdown.sh. In that case, Tomcat will use the environment variable values set at the time of invocation.
When doing this, you can set the environment variables prior to running these commands.
The same is true for the Tomcat 6 or Tomcat 7 that Ubuntu distributes as packages.
These neatly separate the $CATALINA_HOME directory (where the Tomcat 7 distribution is supposed to be) from the $CATALINA_BASE directory (where all of the changes and additions for a particular Tomcat instance are supposed to be. For the tomcat7 package, the first directory is /usr/share/tomcat7, while the second is /var/lib/tomcat7.
You can find startup.sh and shutdown.sh in /usr/share/tomcat7/bin and of course you can use them.
However, if you use the Tomcat provided with Ubuntu, you're probably going to want to run it just like any other standard system service, and the packages support this: e.g. in the case of tomcat7, you can just use
sudo service tomcat7 status
sudo service tomcat7 start
sudo service tomcat7 stop
sudo service tomcat7 restart
just like you can for any system service, and it uses the same mechanism as other system services do:
the shell script /etc/init.d/tomcat7 is used to start and stop Tomcat 7
/etc/default/tomcat7 is its configuration file, allowing a few parameters to be set
Using this method, you cannot specify additional environment variables for Tomcat to use by setting them in your shell or in /etc/default/tomcat7; they will not be passed to Tomcat.
However, there is a second method to set environment variables: if you set them in the shell script /var/lib/tomcat7/bin/setenv.sh (or, if you must, /usr/share/tomcat7/bin/setenv.sh), they will be picked up and passed to Tomcat. This method always works.
Finally, Tomcat offers finer control than just using a $CLASSPATH when it comes to specifying additional classes or JARs to be loaded on startup: in its conf/catalina.properties configuration file, you can set the common.loader, server.loader and shared.loader to a list of directories and/or JAR files to be loaded in additional to the standard ones.
All it means is that you should do that as a superuser - which translates to administrator in windows so you should try something like sudo service tomcat7 start
Try export CLASSPATH=/usr/share/tomcat7/lib/servlet-api.jar:/usr/share/tomcat7/lib/jsp-api.jar - This will depend on where your tomcat installation in located.
You can get more here
Cheers
I have the following questions on WAS 8.5 installation:
Can Java 7 be installed outside {or}c:\IBM\Websphere\Appserver
Can the Java 7 name be other than Java1.7_64?
Also how to get the info. using any bat/sh file from IBM
Thanks in advance
No to both: there is no way to change the Java install directory.
To determine the configured JDK, source setupCmdLine and use the JAVA_HOME variable. For example, on UNIX:
. /path/to/profile/setupCmdLine.sh
echo $JAVA_HOME
...and on Windows:
C:\path\to\profile\bin\setupCmdLine.bat
echo %JAVA_HOME%
If you need to automate discovery, you might write a temporary batch file with the following contents, execute it (e.g., using ProcessBuilder), and then parse the resulting output:
#echo off
call "C:\path\to\profile\bin\setupCmdLine.bat"
echo JAVA_HOME=%JAVA_HOME%
I am messing with Tomcat server and I think some strange thing happened. I downloaded Tomcat 7 from apache website (not an RPM but tar.gz). As I understand there should be CATALINA_HOME and CATALINA_BASE environment variables set, but when I do export on my terminal I can't see any of them, but server starts fine through bin/startup.sh and it even says
Using CATALINA_BASE: /home/andrzej/apache-tomcat-7.0.25
Using CATALINA_HOME: /home/andrzej/apache-tomcat-7.0.25
Using CATALINA_TMPDIR: /home/andrzej/apache-tomcat-7.0.25/temp
Using JRE_HOME: /usr/lib/jvm/jre
Using CLASSPATH: /home/andrzej/apache-tomcat-7.0.25/bin/bootstrap.jar:/home/andrzej /apache-tomcat-7.0.25/bin/tomcat-juli.jar
I think that the other day variables were set, but now I tried to use them with keytool to generate certificate and I noticed they are not there.
Am I missing something, because even if I can't see them everything works fine (startup/shutdown and eclipse with tomcat)?
Those environment variables are optional. If there are none set on the system, Tomcat will just set some defaults based on the location of the currently running script (the startup.sh and so on), which will be used as long as Tomcat is running. If you know Shell script language, just open catalina.sh file in an editor and read it.
If you take a look into catalina.sh (which is called from startup.sh) you will notice that in case CATALINA_HOME is not set it automatically sets it to one level above of the program executable:
[ -z "$CATALINA_HOME" ] && CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
and CATALINA_BASE, if absent, is set equal to CATALINA_HOME:
if [ -z "$CATALINA_BASE" ] ; then
CATALINA_BASE="$CATALINA_HOME"
fi
So there's no real requirement for the variables to be set.