There's alot of questions on different forums [1] [2] [3] about this topic but none seem to provide a definitive answer. I've tried different combinations suggested in the various posts but I have yet to succeed.
My goal is to make compiled source code in a standalone tomcat (8) reloadable - just like the embedded tomcat reloads newly complied sources in e.g. spring-boot or Grails. There are a few constraints that I need to comply with:
No Grails or Spring-boot is available
No Maven or Gradle is available
The tomcat should read the exploded war file from an external location
To keep things simple I use a very simple JEE app with Spring MVC as POC for this before I move on to the real deal. The setup is as follows (for now):
Exploded war builds into directory target/exploded
Tomcat is setup with default settings except from Context.xmlwhere the two lines regarding WatchedResource are removed. Context is not set to reloadable="true".
The Tomcat server is run from within IntelliJ Idea (2016.3) like this:
where the "exploded" folder points to the target described above. And the "Server" tab like this:
The server starts up and the app is running fine. I then try to change some code, save it, and build a new exploded war file. I can see the class files change - but nothing is reloaded in tomcat.
Can anybody please elaborate? Is this approach even possible - in contrary to what many posts suggest? How is it possible in the embedded tomcat in e.g. Grails?
Related
I suppose same problem as described in question MSAL for Java quickstart sample app throws exception. When using IDE and deploying to embedded tomcat, app works. After spending one day, I figured out what is the problem.
Application AuthPageController specifies #RequestMapping("/msal4jsample/secure/aad"). This works with embedded tomcat. When deployed to tomcat server, tomcat removes application name from path since it is deployment information and exploded folder name depends on war file name. Same application can be deployed multiple times to different folders. Tomcat maps url as /secure/aad and request in this case is never handled. To fix problem, I created array of request mappings #RequestMapping(value = {"/msal4jsample/secure/aad", "/secure/aad"}).
I forked MS Azure repository and made changes. Please take a look at zdenko-s/ms-identity-java-webapp
There are other fixes too.
War file name is specified in pom.xml, no need to rename it. Removed rename step from documentation also
.gitignore wrongly specifies exclude target. Should be */target
Sharing info. Fix in my forked branch
I am unable to find another article that solves my problem but am happy to hear about one if you know the answer.
I have a RESTful service built in Java with Eclipse. It uses Spring and all of its bells and whistles.
After much work with configuration files, I am able to build the service into a war file, deploy it to my Tomcat webapps folder, and run it from standalone Tomcat. However, it still throws several errors on start when I try to start it from a service defined within Eclipse. The errors are the same errors that I was seeing before I got the config files correct for standalone Tomcat. The errors are about the inability to create the required beans because of references to properties that can't be found.
How did I get it running in Tomcat? I added a couple of .properties files to define properties needed by the beans that get launched at startup and then added a 'set CLASSPATH=...' line to the setenv.bat file in the Tomcat bin folder. This new line adds the properties files into the CLASSPATH. That seems to have fixed everything from standalone Tomcat.
So, my question is, "How do I make these same changes inside my Eclipse server?" I have added the properties folder with the property files under the config folder in Eclipse, just like it is in my native Tomcat folders, but I do not know how to modify the CLASSPATH string to specifically point to my .properties files (as I have done in the setenv.bat file for standalone Tomcat).
I think I understand the problem, but have no idea about the solution.
Thanks for listening.
Dave
Eclipse does not use any *.sh/*.bat files to startup Tomcat. In order to modify the way the server is started you have to open the configuration UI of the server by double-clicking on the server in the Servers view.
From there you will be able to modify the classpath of the system classloader through "Open launch configuration".
Another important setting is "Server path" which tells Eclipse, the value of $CATALINA_BASE. You can modify it only after removing all modules and cleaning the server. It is useful to set it to an easily accessible directory: this way you can verify directly that Eclipse didn't mess up your application deployment (sometimes it "forgets" to copy some libraries).
The "Configuration path" setting tells Eclipse where to find the files (but not subdirectories) that will be copied into $CATALINA_BASE/conf.
Remark: if your application requires you to add libraries to the top classloader, there is probably a problem in your project. The "missing" libraries should be added to WEB-INF/lib of your application instead: look into the "Deployment assembly" of your Eclipse project configuration.
Can anyone tell me..while running servlets iam using apache tomcat. But everytime i make changes to my web application..I have to export the war file and put into the webapp directory again and again..it is too much time consuming and very hectic. For even small changes i have to export war file and then put in my webapp directory. I cant run my web application without doing this..i mean new changes are not reflected till then..
Isn't there any other method..i think auto deploy should do..and however it is set to true in my web application. but it is not doing it..I have been searching on the net since 2 days..but didn't got any solution..please help..
A WAR file is basically just a .zip with the respective webapp contents. Instead of deploying a WAR, you can deploy an "exploded WAR", being the contents of your webapp. Various build tools support doing this, for example, Maven supports the dir packaging in the assembly plugin. Then, you can for example configure your project to build classes directly to your WEB-INF/classes directory of your "exploded WAR".
EDIT: In case it wasn't clear - you just put the exploded WAR within a directory in the webapps directory where you normally put the WARs - so instead of application.war, you just put an application directory containing the webapp.
Most popular IDEs like Eclipse, IntelliJ or Netbeans provide web testing and publishing tools for users, it's a very basic feature.
In case you're using Eclipse, navigating to Web Tools Platform User Guide > Using the server tools in help page, should be sufficient for you to set up the environment.
Here's online help document for Eclipse Mars, for your convenience.
IDE
You can develop with IDEs like Eclipse or Netbeans. It will be easy to develop and auto-deploy will be taken care by themselves. It will save much time. And completely developed final product can be exported at final stage.
As mentioned, the IDEs nowadays can do some rapid redeployment or hot-swapping of classes. This can work for some scenarios but not all.
JRebel
For even more advanced hot-swapping in more scenarios, consider the commercial tool JRebel by ZeroTurnAround.com.
I am new to web applications in java and need a bit of help with this. I have a multi module project set up in eclipse, which also contains WEB-INF/lib directory of the WAR.
In the non-web version i can debug though it fine however when i deploy it to weblogic i am encountering errors which i dont get on my local workspace, so i'm trying to deploy it using tomcat. I installed tomcat and deployed the war file onto it. I see a blank page (which is normal - essentially the application has a listener, i send it a jms message and that kicks off the process afterwards) but i dont know how to put a break point so i can step though the code - line by line - if this is possible?. Would appreciate some references / reading material.
We are in the process of upgrading from Jetty 9.0.6 to 9.1.1 and are working through the configuration changes to complete the transition. Our application has numerous web contexts deployed, all of which use a common set of libraries (apache commons, logging, specific db, etc) located in an external directory (i.e. - outside of the Jetty deployment).
In Jetty 9.0.6, we included a parameter on start-up which referenced the top level directory for these common libraries:
java -jar .\start.jar lib=M:\common\lib
In the cutover to Jetty 9.1.1 the flag has been changed to --lib. Using the --list-configs we've verified that the directory is in the classpath created by start.jar. However, when the application is started, we are getting numerous ClassNotFound issues. All of these errors are for classes contained in jar files that are located in the common library.
This makes me believe that the flag is for either un-jarred classes or a list of specific jar files. We've also tried using the M:\common\lib* and m:\common\lib*.jar to no avail.
I've searched for any reports of a similar issue, but having found none am asking the question. Does anyone know how to pass all .jar files located in a directory to Jetty 9.1.1 on startup?
I've reported this issue on the Jetty site at the following URL:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=428097
Will continue to track further information about the configuration or the issue from there.
UPDATE:
- This issues has been resolved and merged into the Jetty 9.2 code base. For version 9.1.5 we created a custom module that specifies all the .jar files in the directory and that is working fine (although not ideal).
The commonlib.mod file looks like:
#
# commonlib Module
#
[lib]
M:\commonlib\commons-codec-1.4.jar
M:\commonlib\commons-fileupload-1.2.1.jar
M:\commonlib\commons-io-2.3.jar
M:\commonlib\commons-logging-1.1.1.jar
M:\commonlib\commons-net-2.2.jar
M:\commonlib\commons-pool-1.6.jar
Used the command line to add the commonlib module to the start.ini file (although a manual edit would work just fine too).