how to start stop tomcat server using CMD? - java

I set the path for the tomcat and set all variables like
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_22
CATALINA_HOME=G:\springwork\server\apache-tomcat-6.0.29
CLASSPATH=G:\springwork\server\apache-tomcat-6.0.29\lib\servlet-api.jar;G:\springwork\server\apache-tomcat-6.0.29\lib\jsp-api.jar;.;
When I go to bin folder and double click on startup.bat then my tomcat starts and when I double click on shutdown.bat tomcat stops.
But I want using CMD start and stop the tomcat.
And in any folder I write command startup.bat the server will start and when I write shutdown.bat the server will stop.

Add %CATALINA_HOME%/bin to path system variable.
Go to Environment Variables screen under System Variables there will be a Path variable edit the variable and add ;%CATALINA_HOME%\bin to the variable then click OK to save the changes. Close all opened command prompts then open a new command prompt and try to use the command startup.bat.

Steps to start Apache Tomcat using cmd:
1. Firstly check that the JRE_HOME or JAVA_HOME is a variable available in environment variables.(If it is not create a new variable JRE_HOME or JAVA_HOME)
2. Goto cmd and change your working directory to bin path where apache is installed (or extracted).
3. Type Command -> catalina.bat start to start the server.
4. Type Command -> catalina.bat stop to stop the server.

This is what I used to start and stop tomcat 7.0.29, using ant 1.8.2. Works fine for me, but leaves the control in the started server window. I have not tried it yet, but I think if I change the "/K" in the startup sequence to "/C", it may not even do that.
<target name="tomcat-stop">
<exec dir="${appserver.home}/bin" executable="cmd">
<arg line="/C start cmd.exe /C shutdown.bat"/>
</exec>
</target>
<target name="tomcat-start" depends="tomcat-stop" >
<exec dir="${appserver.home}/bin" executable="cmd">
<arg line="/K start cmd.exe /C startup.bat"/>
</exec>
</target>

you can use this trick to run tomcat using cmd and directly by tomcat bin folder.
1.
set the path of jdk.
2.
To set path.
go to Desktop and right click on computer icon.
Click the Properties
go to Advance System Settings.
then Click Advance to Environment variables.
Click new and set path AS,
in the column Variable name=JAVA_HOME
Variable Value=C:\Program Files\Java\jdk1.6.0_19
Click ok ok.
now path is stetted.
3.
Go to tomcat folder where you installed the tomcat.
go to bin folder.
there are two window batch files.
1.Startup
2.Shutdown.
By using cmd
if you installed the tomcate in D Drive
type on cmd screen
D:
Cd tomcat\bin
then type
Startup.
4.
By clicking them you can start and stop the tomcat.
5.
Final step.
if you start and want to check it.
open a Browser in URL bar type.
**HTTP://localhost:8080/**

Change directory to tomcat/bin directory in cmd prompt
cd C:\Program Files\Apache Software Foundation\Tomcat 8.0\bin
Run the below command to start:
On Linux: >startup.sh
On Windows: >startup.bat
Run these commands to stop
On Linux: shutdown.sh
On Windows: shutdown.bat

Create a .bat file and write two commands:
cd C:\ Path to your tomcat directory \ bin
startup.bat
Now on double-click, Tomcat server will start.

I have just downloaded Tomcat and want to stop it (Windows).
To stop tomcat
run cmd as administrator (I used Cmder)
find process ID
tasklist /fi "Imagename eq tomcat*"
C:\Users\Admin
tasklist /fi "Imagename eq tomcat*"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
Tomcat8aaw.exe 6376 Console 1 7,300 K
Tomcat8aa.exe 5352 Services 0 124,748 K
stop prosess with pid 6376
C:\Users\Admin
taskkill /f /pid 6376
SUCCESS: The process with PID 6376 has been terminated.
stop process with pid 5352
C:\Users\Admin
taskkill /f /pid 5352
SUCCESS: The process with PID 5352 has been terminated.

There are multiple ways to Start and Stop Apache Tomcat Server in Linux and Windows Operating systems. Below is detail facts. Locate the bin folder in your tomcat server and execute the following commands in CMD/ Terminal.
Linux:
./catalina.sh run
Passing "run" argument for catalina.sh --> starts the Tomcat in the foreground and displays the running logs in the same console. when the console terminal is closed it will terminate the tomcat.
./catalina.sh start | ./catalina.sh stop
Passing "start" argument for catalina.sh --> starts the Tomcat in the background. Since in background no issues closing down the terminal. The logs need to be viewed as below: tail -f $CATALINA_HOME/logs/catalina.out
./startup.sh | ./shutdown.sh
The last way is firing the startup.sh to start your Tomcat server. If you Vi the script you can see it calls catalina.sh script passing start as the argument. This will be running in background as well.
Windows:
startup.bat // start tomcat server
shutdown.bat // stop tomcat server

You can use the following command
c:\path of you tomcat directory\bin>catalina run

Related

Jenkins slave on windows doesn't show logs

I have Jenkins master on Ubuntu host in docker containers, connected to it is a windows slave that i run Jenkins on it using a PowerShell script that launch the agent:
java -jar agent.jar -jnlpUrl http://XX.XX.XX..../jenkins-agent.jnlp -secret XXX... -workDir "/jenkins"
we start the launch agent script using this script that creates the job:
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $trigger -FilePath start_agent.ps1 -Name MyJob
my issues is:
when i go to the master UI and go to the slave node - i press on "logs" but it doesn't show anything, it just loads forever with 3 dots loading
I tried to redirect logs using *>&1 > output.txt at the end of the java -jar command but it doesn't work. and I haven't found any java jar argument that works in redirecting the output have tried -XX file path , couldn't find the Log4j file
i have a directory in the windows jenkins path named "remoting" and it has logs but it only have restart logs and not live logs\error logs and i need it.
Thanks.

How to redirect Tomcat system.out and system.err to a file, if it starts as service?

I need to redirect any Tomcat output to a file, I saw some people suggesting add some command line parameters, but I starting it not with command line. Tomcat installed on CentOS and I configured it to launch on system startup (using systemctl enable tomcat). I can launch tomcat manually, but there is no startup.sh or catalina.sh scripts (/bin folder contains only bootstrap.jar, catalina-tasks.xml, tomcat-juli.jar) and find / -name catalina.sh returns nothing.

How to launch a jar file on windows startup from the registry?

I am trying to launch a jar file on Windows Server 2008 R2 startup.
I tried to add a key\value to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
I tried as a value several alternatives:
java -jar c:\jcm\jcm.jar
"java -jar c:\jcm\jcm.jar"
c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar
"c:\program files(x86)\java\jre1.8.31\bin\java.exe -jar c:\jcm\jcm.jar"
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
But none of them launched the program.
Can you advise please?
EDIT: Fixed exe to jar of course
You probably have a problem in the command line. I think it should be something like that last row that you have used but with jar and not exe.
"c:\program files(x86)\java\jre1.8.31\bin\java.exe" -jar c:\jcm\jcm.jar
You just need to test it in command line first and if it works it will work in the registry. You can also make a .bat file to start the java program and copy that to windows Startup Folder instead of using the registry.
The startup folder you can find here:
http://windows.microsoft.com/en-us/windows/run-program-automatically-windows-starts#1TC=windows-7
If it is Windows 10 then you may try this way-
Create a batch file e.g. (my-batch.bat with below statements.)
#echo off
title my-app batch script!
echo my-app welcomes you!
:: If your JAR contains GUI then use-
start javaw -Xmx200m -jar D:\Softwares\JAR\my-app-v1.0.jar
:: Otherwise use-
start java -jar D:\Softwares\JAR\my-app-v1.0.jar
Copy this my-batch.bat file at
C:\Users\pc\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Restart your PC to execute your JAR on startup.
Now, You may check your running JAR using Command Prompt with below commands-
1. jps -l
Output will look like-
8120 sun.tools.jps.Jps
13276 D:\Softwares\JAR\my-app-v1.0.jar
2. tasklist /V

.BAT files: Launch the JVM in background

Having read the post at .bat files, nonblocking run/launch,
I still cannot achieve what I need: to have the .BAT file close once the start command is executed. My problem is that when the JVM starts the application launches a window so I end up with 2 windows being opened, when in fact one of them (the .BAT command) is just a startup process and doesn't do anything meaningful to the user.
I paste the .BAT code here:
#echo off
setlocal
rem Starts the application
rem Check for Java Home and use that if available
if not "[%JAVA_HOME%]"=="[]" goto start_app
echo. JAVA_HOME not set. Application will not run!
goto end
:start_app
echo. Using java in %JAVA_HOME%
start "Application" "%JAVA_HOME%/bin/java.exe" -jar lib/pathToMyJarFile
goto end
:end
I'd like the .BAT process to terminate (or at least the window to close) once the JVM starts.
Try javaw.exe instead of java.exe.
Use start /b, see this:
http://zeroflag.wordpress.com/2007/05/12/start-command/

How to change java_opts for tomcat when we run it as a windows service manually?

I'm manually running tomcat 6 as a windows service on the console. I need to change java_opts before starting it. How do I do that? Also, Is there a way I can see the logs dynamically?
I know this is an old thread but needed to correct some assumptions.
Just an FYI, Catalina.bat is not utilized when running tomcat as a service. here is the method to change the JAVA_OPTS for tomcat running as a windows service.
Open Services and click on the Tomcat service. Make a note of the service name (most likely Tomcat6).
cd to the Tomcat bin directory
Run the command
tomcat6w //ES//Tomcat6 (substitute your service name if different)
Click on the Java tab
Add the options (each on a new line) to the Java Options box and set the initial and max memory to 1536 and 2048
-XX:MaxPermSize=256m
-Djava.awt.headless=true
-Djava.net.preferIPv4Stack=true
Click apply
Click on the general tab and restart the service
To change the settings, create a file named setenv.bat for windows or setenv.sh for Linux with entry as below:
Windows:
set JAVA_OPTS="-Xms256m -Xmx512m"
Linux:
export JAVA_OPTS="-Xms256m -Xmx512m"
Simply put this(setenv.bat/setenv.sh) file in %CATALINA_HOME%\bin\ folder. Your command file (catalina.bat/catalina.sh) already has a statement as below:
Windows:
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
Linux:
if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
. "$CATALINA_BASE/bin/setenv.sh"
elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
. "$CATALINA_HOME/bin/setenv.sh"
fi
This will take care the rest.
To alter the $JAVA_OPTS, you will probably need to edit the batch file you use to start Tomcat. I don't run Tomcat on Windows, but the $JAVA_OPTS appears in my catalina.sh inside the bin/ directory on my Linux installation.
As far as viewing logs dynamically on Windows, there are a couple of options I'm aware of.
Download and install Cygwin, and then on the command-line, use tail -f logfilename like you would in Linux.
Get the BearTail program and use that to follow your log files.
You can set your JAVA_OPTS environment variable either manually via the command line prior to starting Tomcat:
set JAVA_OPTS=youropts
or you can edit catalina.bat with the values you want.
In windows, cut the quotes on the set command. Quotes are taken literally.

Categories