I am doing development of a web app with Java. My current process is to export the project as a WAR to the Tomcat folder, where it picks it up and reloads the WAR. I wait for it to run through its startup process and away it goes.
I would like to make it not need to do an entire reload when it isn't necessary. If I'm making a small change to a single class, perhaps it could reload just that class. If I'm changing static content, perhaps it could just send that HTML file or JS file.
How can I achieve this? My only real dealbreakers is that I need a solution that works with Eclipse. I'd even consider a different container than Tomcat, although it's where I'm familiar.
You can hot reload/deploy your application inside Eclipse , but for seperate Tomcat server , I don't think hot reload is possible .
For Eclipse
For eclipse , you can follow the instructions in this link https://mkyong.com/eclipse/how-to-configure-hot-deploy-in-eclipse/
This will speed up your development , but it has it's limitations
Hot deploy will support the code changes in the method implementation only. If you add a new class or a new method, restart is still required.
For Tomcat
I haven't tried it , but all the class files of war will be loaded/rendered from binary memory of Tomcat . So try changing the class files in that location(Not sure about the path of binary class folder ) .
But if you want to render static HTML,js and css from tomcat server , it can be easily done adding another folder inside "webapps" folder (eg : /webappps/static)
Related
Hi In my project I have many many jars.
Every time I change code and need to upload it to the server takes very long time, because I m adding the jars to the war to be deploy on tomcat.
I m trying to put all the jars in the server, in some folder and to upload the rest of the project only, to speed the cycle.
What will be the best way of doing that ?
I m using tomcat 8.5 also for production deployment without any build tool.
I would like to set an ABSOLUTE path in the classpath but when doing that in my local machine it won't work after deployment to the unix server.
I never saw where or if I can set an absolute path for the jars (NOT OF THE LOCAL MACHINE)
Thanks in advance
You can read about this in Tomcat docs: Class Loader HOW-TO.
The most simple case and way - put these commonly used jars into $CATALINA_BASE/lib dir - they will be loaded by Tomcat class loader.
But, it doesn't seems to be very nice practice, as mentioned tutorials claims:
Normally, application classes should NOT be placed here.
Personally me, in practice purposes, I would ignore this hint and still place jars inside this folder. But if you want to be accurate, you could create separate path on server (or even inside CATALINA_BASE folder) and place jars there. After that you have to specify this path in $CATALINA_BASE/conf/catalina.propertiesfile in common.loader property:
common.loader="${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
I don't think the issue is isolated solely to my JSPs. However, the current files I'm trying to edit are JSPs.
Whenever I make changes to my JSP, I save the file (in Eclipse), clean/republish my JBoss server, start the server, and access the application (localhost), yet the changes I made are not reflected on the page at all.
I go to the JBoss temp directory to see exactly what version of the file (that I'm editing) the server is currently using. I always see that it's using the original version that I pulled down from the original repo. I have no idea why it's not changing.
I tried re-cloning and re-importing everything just out of desperation, and I'm getting the same results.
In addition, strangely, when I run the command mvn -U clean package -DskipTests=true to do a command-line build using Maven, my file reverts back to the original/unchanged version. (New to Maven, so it's strange to me at least).
So, essentially any changes I am making to files for my project aren't being reflected on my local test server. I'm totally stumped as to why it's behaving like this.
You can put JBoss in development mode. This is a mode in which JSPs are always re-compiled. Thus when you deploy a JSP change, you can immediately see it.
For JBoss 7, edit the file: /jboss/{server_name}/configuration/standalone.xml. Locate the "jsp-configuration" element and set the "development" attribute to true.
<configuration>
<jsp-configuration development="true" x-powered-by="false"/>
</configuration>
Note:
This file is in a different location in different versions of JBoss.
{server_name} in the path above will be specific to your JBoss install. If you have not created a server, then this value is likely "default" for you. You can easily find this value by looking at where your web app is deployed.
It is a good idea to deploy your web application in "exploded" format. That is, rather than deploying it as a WAR file (which takes time to build), explode (i.e. unzip) the contents of the web app right in the JBoss deployment area. That way when you need to make a JSP change, you simply copy the one JSP file.
At the very moment, i have 1 code base for all 7 client. This code is currently manually deploy. If i were to use Jenkins to deploy, any is there any documentation that points me on how to configure Maven/ant &Jenkins to solve the following 3 problems:
Each client has its own parameters and it is configure inside configuration files. Some is in text config properties, some has its very own parameter, some is inside XML and some is in a CSV. Hence, i maintain a separate folder for each client in SVN. Whenever i deploy, i make sure to copy the whole client configuration into the right path.
If new deployment, and since this is a console application, there is no web container to accept a war file and deflate. When i deploy a new whole application folder, and make sure the necessary open source jars are uploaded to the lib folder.
If existing upgrade deployment, i will only deploy the changed application jar, make sure to upload the new open source jars, any new folder(s) and keeping the existing folder untouch.
Item number 2 seems to me is a one time job. but i wonder if anything fancy in jenkins can make item 3 to behave like item 2 (eg: add but not replace)?
Jenkins is not a magic button. It has a lot of great plugins, including some aimed at various deployments, but when you have a set of custom requirements (and yours are custom), you've got to write your own scripts (bash/batch) to achieve that with a combination of plugins.
Instead of using a certain jar in my WEB-INF/lib folder, I want to use its source code (same directory structure and everything) in my WEB-INF/classes folder, so that I may be able to modify its classes more story.
Yet (re)starting my tomcat after deleting the original jar and uploading the corresponding directory into WEB-INF/classes gives me the following error:
SEVERE: Error configuring application listener of class no.something.something1.http.LifecycleListener
java.lang.ClassNotFoundException: no.something.something1.http.LifecycleListener
I am certain that the directory path is the same as the one inside the jar. Also, I have previously tried using classes in my WEB-INF folder for this web application, and tomcat has also been unable to load them, for some reason.
Does anyone know how I go about troubleshooting this error?
Tomcat can only load .class files, it doesn't know what to do with raw source code files. Tomcat doesn't do hot loading of .class files like that anyway. You would have to restart the application or server after you recompiled them either way, packaging them as a .war isn't that much of a burden either way once you automate it.
If you take the time to automate the build and deployment of a proper .war you can just rebuild the .war and it will automagically undeploy and redeploy the application itself, which is many times faster than restarting the entire server.
You can't do what you are trying to do the way you are trying to do it. Tools like JRebel address these issues, but I don't find them as useful as their marketing makes them sound.
You could use embedded tomcat (or embedded jetty) to map directory structure of the application as you like. It probably will require some tinkering if you need some JNDI resources within your application but still worth the trouble.
Here's an example
I have installed and configured tomcat+solr on my personal linux machine and windows as well. I was able to get them working fine. I'm very new to Java and how the file structure works. (i.e. knowing where to put war files and what WEB-INF is) So now that I am ready to install solr and configure it on my clients shared hosting plan, the directions are different from what I did before. I dont want to mess this up and apparently the webserver reboots daily and I dont think I can do it manually which means I have one shot at this every day.
Here is the directions for installing a tomcat servlet on his hosting provider:
http://www.apluskb.com/scripts/Where_do_I_put_my_answer1186.html
As you can see I need to install solr under the html/WEB-INF directory, but read what it says.. its very confusing:
"All Servlets should be uploaded in the /html/WEB-INF/classes directory. Any unpacked custom classes and resources should be uploaded in the /html/WEB-INF/classes directory, while classes and resources packed in Jar files should be uploaded to /html/WEB-INF/lib."
uhh... so which is it? /classes? or /lib? I dont think they explain that very well and I'm a little confused by this statement. Also what exactly do I install? With a normal solr install, solr is put somewhere else, the war file is copied into tomcat and the rest of solr is referenced using some kind of XML configuration file.
Also, since I'm a little new to Java and servlets, can someone explain the tomcat file structure to me (in great detail will definitely get you a +1 from me) and where things should go and why?
Thanks in advance!
Web application structure is defined by J2EE spec, it's not limited (or specific) to Tomcat per se. Here is a detailed tutorial covering its layout. Briefly, however, it's as follows:
There a base (root, home, whatever you want to call it) folder which serves as root of web application, everything else goes under it.
All public stuff (html, images, CSS, javascript, JSP, what have you) goes under that folder (directly or via subfolders).
There's one special folder, also located directly under root, called WEB-INF. It contains non-public stuff, like application descriptor (web.xml), classes (which go into WEB-INF/classes folder), libraries (WEB-INF/lib) and possibly configuration files.
Application can be deployed either using expanded structure above or as WAR (web archive) which is basically an archive containing everything above starting at root folder level (but not including root).
The distinction between classes and lib folders is simple: all packaged libraries (JAR files) need to go into lib; all unpackaged classes (and resource files that need to be in classpath) have to go into classes preserving their directory structure (e.g. com.mypackage.Blah class should go into classes/com/mypackage/)
In your case, it looks like you can only have one web application deployed and it has to be deployed to /html folder. If you're deploying a war file, you need to extract it to that directory (e.g. from within that /html folder run jar xvf solr.war or whatever it's called).