How to debug ant build war files - java

I use ant script to create a war file of my application. Is there a way to debug my application in eclipse?

If you are using tomcat server. Install Mongrel plug-in to your eclipse. After building ant script, just add break points to code and click on tomcat start button provided by Mongrel plug-in. Your app will be automatically running in debug mode. And Mongrel(Tomcat) automatically deploys your war file.
I am currently using the same for my projects.

If you have all the source code in Eclipse and merely use the ant script for building, you should be able to do debugging by just putting the generated war in the deploy folder of your server (or doing whatever else your server requires to deploy a war), and then simply start up your server via Eclipse.
Eclipse wouldn't 'know' that anything has been deployed to the server it has just started, but the connection between WTP's deployer and JDT's debugger is pretty weak anyway. It will simply try to match classes in the JVM to Java files in your workspace. If you have the actual source there this will of course match and you can debug.

Related

How to build, deploy and run Java application on JBoss WildFly from the command line?

My team is working on a Java application that runs on Jboss WildFly, using Maven to resolve dependencies and Primefaces.
We're using Eclipse to build, deploy and run the server. Eclipse does most of the work, building the WAR file, deploying it to server and running it.
Now we need to create an script that performs all those steps because it has to run on remote server.
.
The steps would be something like this...
1 Run Maven:
$M2_HOME/bin/mvn clean install
2 Build project to a war file
3 Deploy war file into the WildFly deployment folder
$WILDFLY_HOME/bin/jboss-cli.sh --connect --command="deploy --force [PATH_TO_WAR]"
4 Start server
$WILDFLY_HOME/bin/standalone.sh
.
I can perform every step but once the server is running it don't seem to be any changes in the application. I think this is because the WAR file has to be built optimizing it for JBoss. Eclipse has a way to do this when exporting the project. I need to know how to do that from command.
EDIT:
The real problem is that Jboss is not updating the published project when i run it from bash script. I thought it was because i had to build it on a specific way. I was wrong. The build is fine, just running Maven the deploy is done. The thing is that even if i rebuild project and redeploy it, server doesn't seem to notice at all.
I've tried deleting tmp, lib and data folders from standalone folder, and nothing happens. I also deleted standalone/deployed sub files and folders and got the same result.
The only way i achieve the result i'm expecting is getting into Eclipse, go to Servers tab, right click on JBoss Wildfly and click on 'Clean...'. This options seems to clean cache, rebuild and re publish the application in a right way that i don't know. I didn't find any answers on google.
eclipse server clean option
Give a look on Eclipse war export: optimize for a specific server runtime.
Quoting from #Konstantin Komissarchik's answer :
Eclipse itself doesn't do anything with that option. What happens is
dependent on a particular server adapter. Many of the adapters don't
do anything with this option either, but they might in the future.
If a server adapter does support export optimization, it has the
option of displaying custom options beneath that pop-up list of
runtimes, so that's a good cue to use to see if something will
actually happen.
So taking in consideration that in your provided image there is no custom options below Wildfly 9 selection, I am pretty sure that this option does not perform any optimization at your exported war so you can totally omit it in your new build-deploy process.
How can i build the war file from command, knowing it will have to run on Wildfly?
We are also deploying applications for a long time on several versions of Widlfy with the same approach as you are planning to, without the optimization thing. I can ensure you that we have not faced any performance issue.

Deploy java web application to Tomcat with Visual Studio Code

I'm trying to deploy a java web application to Tomcat using Visual Studio Code and I'm having some issues that I'd like to share.
After installing the extension Tomcat for Java, I've tried to deploy a Maven Java Web project. To do so, I've clicked over project's folder and selected "Run on Tomcat Server" option. The result is an error with this message: The folder is not a valid web app to run on Tomcat Server.
Then, I've realized that maybe I should create a war file before running it on Tomcat. Therefore, I've executed mvn clean package command and afterwards execute "Run on Tomcat Server" option over the war file. Doing this the project has been deployed correctly.
However, compared to Eclipse's way to work with Tomcat, it seems to me a bit tedious. Particularly if I'm working with static files, like css or js, because every time I modify a file I should execute mvn clean package and "Run on Tomcat Server". Whereas, in Eclipse, these files are deployed automatically on Tomcat without restarting.
I wonder if there is another way to work with VS Code and Tomcat for Java.
Thanks!
If you use Spring, there is an easy way.
The Spring Initializr extension comes with an embedded Tomcat installation, and hot reloading works out of the box.
Rely on the following guide to install it:
https://code.visualstudio.com/docs/java/java-spring-boot

fail to remote debug tomcat with eclipse after deploy a modified jar

I'm developing a datastore plugin to Geoserver, to develop it faster I am trying to remote debug it. Geoserver uses Tomcat behind the curtains. I prepared everything to remote debug via Eclipse and accomplished it. Now I can remote debug my plugin. However, when I modify my code (I tried to add a harmless line like: int noHarm = 5;) and then export it as jar and copy that jar to webapps\lib\ under Geoserver installation directory, I fail to remote debug the plugin. After that I changed that modification back to when it was worked(deleted int noHarm = 5;) and created the jar again, then copied it under webapps\lib\ , now I am able to remote debug again.
When I open stores page in Geoserver, it stops at breakpoints in the canProcess() method with the jar exported from not modified code or when I try to add new Store it stops at breakpoints in the createDataStore() method with the jar exported from not modified code. But if I change even a tiny line or add it won't stop at breakpoints even though it connects to virtual host succesfully(I use vmware workstation with windows 7-32 bit on it if it helps).
What could be the problem?
Thanks very much in advance.
I found the solution, it was about eclipse. My source files was not in the workspace so, in the project build path --> under the source tab I was using Link Source button. That button allows you to link java files (which are not under your workspace) to your project and let those files act as source. What I did to solve this problem:
I then moved those files under project's real source folder
With that I created jar.
I stopped Geoserver(Tomcat) and copied my jar under webapps\lib\
I started Geoserver(Tomcat) and connected to server via eclipse remote debug.
After these steps I was able to remote debug with every jar I deployed.

How to remove reference of a jar file in a java based web application?

I have a java based web application, which has certain java files and due to some need, i have added some jar files with in the project and made it project specific.
Now, While deploying them in production, I see, that the web file server (tomcat6) already has those jar files in its global library. Now, How do i remove reference of that jar file it, with out disturbing my code(which is working fine).
I saw in other article saying we just have to change the build path to refer the global library instead of local library.
Finally I have 2 questions.
How to do this?
If i'm working on windows and using path while configuring the build path, will it not be a problem if i deploy it in Unix environment.?
Please suggest. Also, its the problem with servlet-api.jar.
I use eclipse IDE. So how to perform these changes in eclipse?
Open your web project in eclipse and right click on the project. click on Properties and then choose build path and remove the jars you want to remove under the tab 'Libraries' and then export the war and deploy it in your tomcat6 server. if you want to run your web application in eclipse, you have to configure the server libraries by clicking 'Add Library' button in build path and then choose server runtime and choose the tomcat6 server configured in eclipse. Hope this helps

How to deploy Java project to Tomcat

I have downloaded a sample extjs+mysql+spring web project (link) with a java backend that I'd like to set up locally on my machine. I have installed Tomcat server, and MySQL DB but it's my first time ever with a java-based web application and I have troubles setting it up. Does it require any modifications ? I thought that .jsp files should be included there, but I can only see .java sources. Do I need to build it before it's ready for deployment ? Any help appreciated.
This is an Eclipse project so you'd need to run it from within Eclipse.
Download Eclipse
Open the project in it
Define a Tomcat container in your Servers tab
Drag and drop the project onto the newly defined Tomcat
Run it
if your are using eclipse IDE for development, create a project in eclipse,
run as "run on server" , and set the running server (eg TOMCAT 7).
and thats it,,
make sure, you correctly setup spring project in IDE with all needed jar files .

Categories