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

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.

Related

How to debug WAR application inside eclipse?

I have seen many online tutorial explaining how to use eclipse to do remote debug of WAR file.
But what I want to know is how to do the debug inside eclipse just as debugging a JAVA application? I have Tomcat 7 configured in my eclipse as a server. And I have tested it with a sample servlet program successfully meaning I can set breakpoint in the source code and run into it.
My WAR application is built by gradle. I have imported the gradle project into my eclipse and build it ok inside eclipse by running gradle task inside "gradle tasks view". I added the project into the server. However, when I try to use "Debug as > Debug on Server", it fails and the breakpoint is not get hit. Anyone could share the experience to debug WAR inside eclipse?
I am a IntelliJ Idea user but I have a generic advice here. What you can do is that you can run your application (war/jar etc) with debug port on and then from eclipse use remote debug (or attached to a process sort of option).
Make sure you have exact copy of the code from which you have created war/jar otherwise lines might mismatch while debugging and will be hard to make sense.
On the "Servers" view, select the right tomcat server overview, then go on the "Modules" tab.
There, you can add the war by clicking on "Add External Web Module...".
Set the war path in the "Document base", and what ever you want on the "Path" field.
Example:
Document base: "C:\eclipse-workspace\MyProject\war\myWarToDebug.war"
Path: "/myapp"
Start the server in debug mode. Access your app using the url
<yourServerHost>:<serverPort>/<pathSetInModuleTab>.
Note that when reaching the breakpoint, Eclipse may say there is no sources found. Simply go on the server debug configuration and add the project sources in the "Source" tab.
Before debug you must decompile using jd gui for open class file inside war file and save as java project.

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.

Is there any guide showing how to build effectively an application with appengine and maven in eclipse?

I'm trying to develop an application using Google App-Engine and Maven using Eclipse. I am facing a problem where by whenever you change a CSS or JSP file, a restart of the application is required. This makes working quite difficult, since a reload takes a lot of time.
For example when you develop on tomcat no need for restart is required when such a change is made, only Java or xml file require restart of the server.
Is there a solution that mimics the tomcat behavior on GAE SDK when developing on localhost?
If you've built using the standard app engine maven archetype, when you run mvn appengine:devserver from you -ear directory, the exploded war working directory is located here:
<yourapp>/<yourapp>-ear/target/<yourapp>-ear-1.0-SNAPSHOT/<yourapp>-war-1.0-SNAPSHOT.war
If you change any JSPs in this directory, they will get reloaded without needing to restart the devserver.
Thus, you can set up a simple script or command that copies all your JSPs and static files from /-war/src/main/webapp to that deploy directory whenever you want your files to be refreshed. I saw on some threads where people set up their IDE (in this case IntelliJ) to automatically do that copy whenever the IDE loses focuses, which makes it trivial to get pages reloaded.
Building application with appengine in eclipse using maven is not very effective and time consuming because on every change on jsp/css/js with a traditional approach there is a need to restart appengine or mvn appengine:devserver.
#adevine make me thought about a solution, and I found this link: http://andrei.gmxhome.de/filesync/index.html wich installs a plugin in eclipse, then I activate the project to sync files from myapp/src/main/webapp to a target folder generated by maven myapp/target/myapp-snapshot-0.0.1.
It's working!!!
Whenever a change is done in webapp the files are transfered automtically(no need to run anything else, just save the file) to the target folder and are reloaded successfully.
Hope this could help people because its frustrating working with appengine(restarts takes a lot).

Eclipse Java Remote Project won't build and run

I have spent 6h+ and finally I've decided to seek the community's help.
I have a Java project on a remote SSH cluster and I have imported it into eclipse using RSE (Remote System Explorer). This project used to be a local project and has many libraries/dependencies. I have configured all of them and all of the paths are accessible on the remote cluster.
I want to run it on the remote cluster using SSH as well (via Eclipse External Tools). I have configured EVERYTHING and have even successfully ran another project. However, right now the problem is that Eclipse does not create even a SINGLE .class file on the remote server!!!
The project does not have any errors (if I just copy its bin folder from my computer to the remote cluster it works) but, since Eclipse does not produce a single .class file, there is nothing to run in its bin folder on the remote cluster.
It's also worth mentioning that for some reason that I don't understand, there is a red x on the projects name in Project Exlorer (indicating error) but there is no such thing on any of the source codes/packages in this project.
The "Build Automatically" option is active and cleaning and building it manually won't work either.
Any help is hugely appreciated as I am really desperate and need to get this thing working.
Thanks in advance.
I had a similar problem and this solution worked for me:
In my java context.xml file in the META-INF folder (local project context), I added path="/myProjectName" and it started building automatically.
<Context path="/jvals" antiJARLocking="true" antiResourceLocking="true">
<Resource name="jdbc/jvals"....
I was never able to solve this problem and the only thing I could think of was a bug within Eclipse. It seems that because of slow transfer rates to/from cluster, some of the files could not be built as they were partly fetched/stored. I ended up writing a shell script that would transfer the files to the remote cluster and compiled and ran it on there.
If anyone has a better suggestion, I will be very grateful.
I solve the problem in another way ;
go to the remote project in linux ;
cd youRemoteProject/build/classes
if your jars is in xxx\lib\a.jar, b.jar
java -cp ".;xxx\lib*" package.package.className
( you must using Java 6 or later, classpath wildcards are a part of the JVM )

How to debug ant build war files

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.

Categories