My WAR file doesn't include the latest changes - java

I have made some changes to an existing Java web application. When I deploy this file to Apache, via WAR file, it regenerates the website as it appeared before my changes.
I delete the existing website directory before deployment, and I've moved out all existing WAR files. I have committed my changes to source control and recreated the WAR file, but still no effect. I even added a small text file to the solution and that was included in the WAR file and deployed to the server, but still my changes were not active.
I am using Spring as my IDE to create the WAR file, and Apache Tomcat to host the website.
Why aren't my changes being packed in the WAR file?
EDIT: I am very new to Java, but have plenty of experience in .NET. Please excuse stupid questions from me.
EDIT 2: As far as I can see, the changes are actually included in the WAR file and are deployed to the server (the class files contain certain strings that they never did before). But the code just isn't executing as it should with those changes (despite Tomcat and the machine itself being restarted).

Maybe try to add Maven to your project and then try to use mvn package to make a war file. Some time ago I had a similar problem. I tried to build a war file without Maven and changes on Tomcat weren't seen. Then Maven helped me out.
Edit:
Convert Existing Eclipse Project to Maven Project
http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/
Maybe this could help you.

Related

How to package java libraries that will automatically work when jar file is distributed to another computer?

I've created an application which has a few external libraries, i am trying to distribute to another machine. I want the application to work from just the .jar file.
I know its something to do with the 'Resolve Project Problems', is there a way to prevent this when distributing to another machine
I have already tried adding a library to the distribution folder, it carries over but doesn't do anything with it
Run the application on a new machine without having to 'Resolve project problems' through net beans
You will need to Create a FAT jar
Two Useful links which helped me where
How to include jars in lib into project jar file in Netbeans?
https://dzone.com/articles/java-chronicle-bytes-kicking-the-tires
This didn't entirely fix the issue, i was using a dynamic file string with in my program
I copied the data folder from my application and pasted it in the store folder and rebuilt and also repackaged the fat jar. This made it work

How and when to clean and restart while editing code on tomcat production server

This question is going to consist many subquestions.
in eclipse I clean the project after making changes in .java or .xml files.How can I clean it using command line?
What exactly clean and build does? cleaning is same as that of restarting a server?
What scenarios(developer point of view) requires Server restart?
editing css, html doesn't require server restart.On what file edits I should restart the server?
Server.xml and context.xml requires restart or not?
in eclipse I clean the project after making changes in .java or .xml
files.How can I clean it using command line?
You can run javac from command line, but its not going to be very convenient. Recommend using a build tool like maven (or at least ant) for building your project. These tools can be run from command line and create your war
What exactly clean and build does? cleaning is same as that of
restarting a server?
Clean deletes the classes folder and build compiles your source code and creates the classes folder and the .class files
What scenarios(developer point of view) requires Server restart?
You can use tomcat manager to hot-deploy your war so a server restart is not required - however you probably should not be doing this in production.
editing css, html doesn't require server restart.On what file edits I
should restart the server?
Any changes to java files (deployed in WEB-INF/classes) or jars (in WEB-INF/lib) require a server restart - actually anything in WEB-INF. Any changes to css/html will also require you to re-deploy in case you are deploying as a war. A reploy is not needed in case you are using an exploded war (which I guess you are)
Server.xml and context.xml requires restart or not?
Changes in server.xml require a restart. Changes in context.xml at least require a re-deploy

Correctly Deploy maven project

I have a project with maven, this a multimodule project
Mainproject
project1 - jar
project2 - jar
project3 - web
Now that I finished the project I want to test it on the server but don't know how to upload them, on my computer I have added a plug for tomcat which deploys the war file to tomcat automatically, but the server doesn't have maven.
What is the way for moving to production with this kind of projects?
Should I just upload the target directories for each module?
Thanks
You're asking a few questions here. There is the "how do I test on a server" one, and there is "what is the way for moving to production" one. And they can be quite different.
I have assumed that the JAR files in the project are used by the WAR file and packaged within its WEB-INF/lib directory. If I'm wrong, that's cool. Just this sort of information is handy to know.
Maven is a build tool. It is not a deployment tool. What you have at the end of this, is a WAR file. If you run mvn install (or mvn deploy) you have a SNAPSHOT version of the WAR file. This would be suitable for quick, ad-hoc testing to other machines. But you would most likely use methods approriate for the hosting container for making them available. Note: a Maven DEPLOY is a different thing from a DEPLOY a war file to tomcat.
To my mind, if you're putting anything into production, or in front of a customer, or in front of a testing group, you should use Maven to make a Release of the product. That is, using the release plugin (via the release:prepare and release:plugin goals) to create a non-SNAPSHOT release of your artifact (in this case, a official version of the WAR file). Once you have that WAR file, you can migrate it to your production server in whatever way is easiest (copy, deploy into tomcat in the best way). You haven't mentioned if there are database requirements for this web application, and that would need to be considered before you change any production application.
But, once you have official versions, you have tags of source code, and you can accurately know what code is being run.
What I don't think you're going to get is being able to automatically copy the WAR file into a production server from your development environment. Here be dragons.

Does the Google-Eclipse plugin autogenerate war directory contents?

I just created my first Web Application Project using the Google-Eclipse plugin. Amongst other artifacts, it autogenerated a war/ directory with several subdirectories and many files, including:
war/
WEB-INF/
lib/
<Lots of JARs here>
web.xml
appengine-web.xml
etc.
Several times now I've cleared out certain parts of this war/ directory (messing around with buildscripts and other Google-Eclipse plugin features - this is just a test/temp project for getting used to the plugin), and they magically reappear at some point in the future.
I'm wondering if, because I set this up as a Web Application Project (and it is thus managed by the Google-Eclipse plugin), is the plugin trying to preserve the structure of the war/, and as such, continuing to auto-generate any missing files?
If so, why? Exactly (which files/directories) what is it trying to preserve? Can I disable it?
And if not, then I obviously have something else going on here. In which case, has anybody else ever experienced this with the Google-Eclipse plugin, or just Eclipse in general? Thanks in advance.
This plugin only updates war/lib directory by adding dependencies. Actually it just copies jar files when you switch to a another version of Google App Engine SDK.
This should not be a problem.
War folder is the exploded package that later on you need to deploy to Google App Engine.
When you build or deploy file to GAE, this folder will be re-created/updated, and it contains the newly compiled jar and the necessary libs.
Read this.
War folder contains the generated javascript files which are deployed to the app engine.

HTTPClient on Tomcat

I really apologize if this is a silly question.
I have a tomcat server running on a unix machine. I want to use the HTTPClient library. Does it come pre-bundled with tomcat or do you need to install it?
If people say to just add it to your class path. Should I download the source or the binary from here:
http://hc.apache.org/downloads.cgi
Once downloaded is there a way to auto install it using a .tar.gz as I think I have done this in the past. If not is it just a case of putting the folder on the drive and adding it to the classpath?
TIA
Each web application is supposed to package its own dependencies inside the deployable WAR file. It is an ill-advised practice to extend Tomcat's global library with any library an application might need.
On the WAR building front, the common practice you should stick to is not to manage dependencies on your own; it quickly turns into a nightmare. Configure your project with Maven , which will both manage the dependencies and build the WAR for you.
Just look for httpclient....jar file in the Tomcat directory. If there is none there, then put it inside the lib directory :)
You should download the appropriate jar file. It contains portable library code. Once placed in the classpath, Tomcat will find it. Tomcat directory has a lib subdirectory. This is global classpath part for all web applications.

Categories