Intellij tomcat local run configuration - what happens behind the scenes? - java

I've been using tomcat run configuration without any problems - it does a excellent job. However I kind of don't like the fact that it is not documented anywhere (or is it?) how this magic actually happens.
I suppose it somehow makes tomcat reference app created from artifact within target directory (if using maven). I also noticed that when using manager-gui app there are no other applications deployed so it must not use tomcat/webapps dir.
What I am curious is:
How does it start tomcat to point at the application outside tomcat home?
Does it deploy my app using {project_dir}/target/{appName}?
Where is the manager-gui app?
Where are the logs and conf files?

I'm using IntelliJ IDEA 15.0.3, Tomcat 8.0.15 and JDK 1.8.0_31
This is an excerpt from C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.2\bin\idea.properties:
#---------------------------------------------------------------------
# Uncomment this option if you want to customize path to IDE system folder. Make sure you're using forward slashes.
#---------------------------------------------------------------------
# idea.system.path=${user.home}/.IntelliJIdea/system
idea.system.path=D:/dev/IntelliJ-Settings/system
In File --> Settings... --> Build, Execution, Deployment --> Application Servers I've defined this: (look at Tomcat base directory)
D:\catalina-base-idea contains the global Tomcat configuration for IntelliJ.
When I deploy my webapp using IntelliJ run configuration, the web app will be deployed to D:\dev\IntelliJ-Settings\system\tomcat (see idea.properties).
The above explains question 1.
Question 2: afaik, target is only used for building, not for deploying.
Question 3: there is no manager app within D:\dev\IntelliJ-Settings\system\tomcat\webapps
Question 4: logs are within D:\dev\IntelliJ-Settings\system\tomcat\webapps\yourApp . The global Tomcat config is located in D:\catalina-base-idea.
You can configure the Tomcat for IntelliJ so that it uses a port other than 8080. So you can start your standard Tomcat and IntelliJ Tomact at the same time.

Related

change in configuration/setting without restarting Tomcat

Ideally what I want to be able to do is load in a fresh copy of the config if a change is detected so that if it is updated in the DB, it gets fetched and updated in the application without a restart.
I tried to add autodeploy = true inside host, server.xml and reloadable = true inside context.xml.But none of this worked.
Is there any other solution for this. Iam using eclipse IDE and my sever is Tomcat.
I read adding inside context will help for this.
<Context reloadable="true">
<!-- Default set of monitored resources -->
<WatchedResource>Config/Design/configs/globalconfig</WatchedResource>
But this one still din't help me.Am I giving the path in wrong way or something?I got this from the following link https://www.mulesoft.com/tcat/tomcat-reload
Edited Besides I tried with the auto reload on module, disabled and enabled as well. And also noting one more thing here I don't want to use JRebel.
If I go by the heading of the question
change in configuration/setting without restarting Tomcat
I would agree with Jomcy Johny, that the design approach perhaps need to be reviewed. In continuation to the above comment, perhaps you should consider keeping the configuration outside of the container. There are many way of achieving the same, one possible direction is with Apache Zookeeper.
On the side note, the path mentioned in the Mule document is generally of form 'WEB-INF/x/yz' or '/Dir0/config.file'.
It is possible to deploy web applications to a running Tomcat server.
If the Host autoDeploy attribute is "true", the Host will attempt to deploy and update web applications dynamically, as needed, for example if a new .WAR is dropped into the appBase. For this to work, the Host needs to have background processing enabled which is the default configuration.
autoDeploy set to "true" and a running Tomcat allows for:
Deployment of .WAR files copied into the Host appBase.
Deployment of exploded web applications which are copied into the
Host appBase.
Re-deployment of a web application which has already been deployed
from a .WAR when the new .WAR is provided. In this case the exploded
web application is removed, and the .WAR is expanded again. Note that
the explosion will not occur if the Host is configured so that .WARs
are not exploded with a unpackWARs attribute set to "false", in which
case the web application will be simply redeployed as a compressed
archive.
Re-deployment of a web application if the /WEB-INF/web.xml file (or
any other resource defined as a WatchedResource) is updated.
Re-deployment of a web application if the Context Descriptor file
from which the web application has been deployed is updated.
Re-deployment of a web application if a Context Descriptor file (with
a filename corresponding to the Context path of the previously
deployed web application) is added to the
$CATALINA_HOME/conf/[enginename]/[hostname]/ directory.
Undeployment of a web application if its document base (docBase) is
deleted. Note that on Windows, this assumes that anti-locking
features (see Context configuration) are enabled, otherwise it is not
possible to delete the resources of a running web application
Above is a snippet from Apache tomcat And also most of the general idea about hot deployment I gained from hot deploy
Reloading Context elements when they are within the server.xml is not likely to work as "...server.xml file cannot be reloaded without restarting Tomcat"[1].
What you can try, is creating a file at "/META-INF/context.xml"[1], and adding the context in there.
Then you can replace the war file if with the new context files without a server restart.
Or you program a server restart in if needed. See [2]
source:
[1] https://tomcat.apache.org/tomcat-8.5-doc/config/context#Defining_a_context
[2] Java - Tomcat: Reload context.xml without restarting server
You can write a script and run it as a service outside your application to keep a track of your config file's last modified time, in case of a change you switch to your Tomcat container and run the following command (considering OS is Linux):
source ~/.bashrc
(In case of windows, its done as soon as you change environment variables and save.)
Hope that this helps.

JRebel not working on external tomcat 7

For some reason I can't get JRebel work on external Tomcat 7 with Eclipse. Everything works fine if I use server runtime in IDE, but if I launch server from command line and deploy application externally, JRebel doesn't reflect my changes to server.
Here is how I configured and deployed my project:
Enabled JRebel on project from projects configuration tab
Startup set to Run locally from command line
Created catalina-jrebel.bat according to generated configuration
Built project using maven
launched server using catalina-jrebel.bat run
Deployed war file on server from Tomcat's application manager
Now, if I modify my sample Servlet and save, nothing happens. Application behavior doesn't change, nothing in console.
Am I missing something, and how to debug the problem?
Here is the content of catalina-jrebel.bat
#echo off
set REBEL_BASE=C:\Users\tutoivon\.jrebel
set JAVA_OPTS="-javaagent:C:\SLO\eclipse\plugins\org.zeroturnaround.eclipse.embedder_6.4.4.RELEASE\jrebel\jrebel.jar" %JAVA_OPTS%
call "%~dp0\catalina.bat" %*
Some things you can check by yourself:
Server starts up with JRebel banner - so you can be sure JRebel Agent was actually attached to server.
In the banner it says that you have valid license - no license, no reloading.
The built .war contains a rebel.xml inside WEB-INF/classes - this helps JRebel to find the location of classes updated by IDE.
The paths in rebel.xml are absolute and correct, no placeholders (e.g. ${rebel.workspace.path}) are used - if placeholders are used, then they must be defined by passing e.g. -Drebel.workspace.path=/path/to/workspace to JAVA_OPTS. If done correctly, JRebel will also log a line such as JRebel: Monitoring directory '/path/in/rebelxml' in server log.
If you still can't get it to work after these steps, contact support#zeroturnaround.com.

Unable to open "Tomcat web application manager"

I am new to java web programming and eclipse-apache Tomcat. I have small login web-application which includes (one jsp page , one servlet class).
I want to configure/deploy this application on apache web application manager. I mean I don't want to run this application in eclipse. I hope you understand my point.
Whenever I run my server in eclipse it run successfully. But when I want to open apache default page by typing http://localhost:8080 or http://localhost:8080 to configure my app It wouldn't open.
Please advice me.
To deploy a web application on Tomcat, you need to first compile your web application into a WAR file. Then, take that WAR file (let's assume it's called "MyApp.WAR") and put that into the tomcat/webapps directory. Restart the tomcat service. Tomcat will extract that WAR to a folder in the webapps directory. After that, any request to localhost:8080/MyApp will go to your webapp.
Make sure you have java installed, and add JAVA_HOME to your environment variable. (it is the path to java installation directory for e.g. C:\Program Files\java\jdk-1.6)
i.e
JAVA_HOME=C:\Program Files\java\jdk-1.6
install TOMCAT from here "http://tomcat.apache.org/download-70.cgi"
make sure you do not install it in you "c:\program files" due to some permission issues.
Lets say you installed tomcat at "c:\webserver\apache-tomcat\" this is your CATALINA_HOME, add it to your environment variable
i.e CATALINA_HOME=c:\webserver\apache-tomcat\
to acess tomcat webapp manager you need to configure user in %CATALINA_HOME%\conf\tomcat-users.xml
Add a role and a user :
Have your WAR file ready with you (this is how you create WAR "How to make war file in Eclipse")
move your WAR file to "%CATALINA_HOME%\webapp" directory. lets say "TestWeb.WAR" is your application with index.jsp page in it.
Now go to your %CALALINA_HOME%\bin and launch the startup.bat file (you would be using startup.bat to start and shutdown.bat to stop tomcat)
once tomcat is up and running check http://localhost:8080 is working fine.
P.S. If port 80 is already in use then try configuring your tomcat to some other unused PORT here "http://www.mkyong.com/tomcat/how-to-change-tomcat-default-port/"
go to your browser type http://localhost:8080/TestWeb/index.jsp
now you can to lot of configuration to your web app like having a default page and all
Hope this help you !
Normally eclipse uses Tomcat as an eclipse project, hence it uses metadata.
Server > Double click on the tomcat server instance > Server Location > Select "Use Tomcat installation"
Update: Tested just now. Set Deploy path to webapps folder. Works fine :)

Tomcat interrogation with eclipse under linux/mac

I added my local tomcat 8.0.14 with eclipse successfully. My local tomcat is located at /Users/masum/tool/tomcat-8.0.14. I can see it form eclipse runtime Environment as well. Whenever I deploy any webapp to eclipse's tomcat. It doesn't appear in local tomcat-8.0.14/webapps directory. I expected it should go there. But it doesn't.
Also is I do any changes in tomcat/conf/server.xml. These changes doesn't effect in eclipse integrated tomcat. Also if local tomcat is running, port number conflicts with eclipse's tomcat. I have to stop local tomcat to work with eclipse tomcat. Looks like two different instance of tomcat.
My question is where does eclipse tomcat physically located? If I deploy any web app in eclipse tomcat where it actually goes? How can I configure Tomcat so that I can control it both from eclipse and also manually?
Thanks in advance.
Double click your tomcat server in the servers tab. In the servers tab you will see "Server path" under server locations. This is the location of eclipse's tomcat working directory. If you stop tomcat and undeploy all web apps, start and stop again, you will be able to select other options. Click "Use custom location" to set the location to a place of your choosing. In project Explorer you should see a tomcat folder. Under that folder you will find server.xml and the other config files, which you can modify as needed.

Can I configure Eclipse / JBoss integration so it does not rely on deploying Jars to the "server/default/deploy" folder?

I am using MyEclipse 7.5 with JBoss 4.2.3 GA.
When I define my local development JBoss server in MyEclipse it always wants to deploy jars, wars etc. to the "server/default/deploy" directory.
Unfortunately our JBoss directory structure for production is "server/XYZ/deploy/abc" (driven by a third party).
As a result our Dev JBoss instances are different from our QA/Staging/Production JBoss instances.
Is there a way to configure Eclipse to use JBoss but deploy to that specific folder path "server/XYZ/deploy/abc" rather than the default one "server/default/deploy"?
With MyEclipse IDE, you can change deployment location for Project. Just click on Windows->Preferences->Servers->JBoss.
Select proper Jboss - For eg. JBoss
5.x, here you have to set Jboss home directory, For eg. 'd:\Jboss5.0GA'.
In 'Server Name' field if you specify 'default' then project deployment
directory will be for eg.'d:\Jboss5.0GA\server\default\deploy'.
As in your case, you may specify any other 'Server Name', then deployment
location will get modified accordingly.
For eg. if server name is :'XYZ' then
deployment location:
'd:\Jboss5.0GA\server\XYZ\deploy'
.Make sure you have all configuration
folders (like conf,lib etc ) at 'server\xyz' as in
'server\default' folder.
There is probably a better answer that uses MyEclipse configuration to do exactly what you want, but I wondered if you could use a directory soft-link, like this:
ln -s server/XYZ/deploy/abc server/default/deploy
to allow applications to work with the production directory as if it were the default?
This only works on Linux, Unix, OS/X; but Windows Vista and later has similar functionality.
You can create links by Far Manager.
Alse read this - Symlink in windows XP

Categories

Resources