What is "remote debugging" on tomcat? - java

I'm not asking how to do it. I'm asking what it is. I asked my coworkers if we could setup remote debugging on our smoke-testing server and step through the code in eclipse from our developer PCs, and they looked at me funny.
Does remote debugging mean something other than "debug just like always, but remotely, with an IDE on your computer and the application running on a different machine"?
I've never done it and it looks like something that will take me hours to setup, and I doubt I could get permission to research it just to find out if it is what I hoped it was, so I'm asking you all if it is what I hope it is.

Yes, you can start the server in debug mode and connect to it from another machine using Eclipse. It is not hard to setup, read here: http://wiki.apache.org/tomcat/FAQ/Developing
It works exactly as you describe, using JPDA: http://en.wikipedia.org/wiki/Java_Platform_Debugger_Architecture

Related

Setting property to disable ehcache at tomcat startup

I am new to this project and still figuring many things out. Been an experienced web developer for many years now.
My QA people came to me and said, "We're having an issue. We used to be able to turn off hibernate caching on our QA boxes to run queries outside of the app and then see the results in the app, but it's not working any more."
So I look into the problem and they we adding the following line to setenv.bat (Tomcat 7 running on Windows Server 2012 R2 Standard),
set JAVA_OPTS=%JAVA_OPTS% -Dnet.sf.ehcache.disabled=true
and this, according to them used to work, but now it doesn't.
So, problem one, is that we don't run the app in the same way on our dev boxes than on QA and in production. (I know, I know.) We run maven scripts to start everything and I can get the java opts thing to work just fine.
Funnily, I've been doing this for years and I didn't know anything about setenv.bat. I did some reading here: https://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt and it says that setenv.bat doesn't work when running tomcat as a service.
So, I log onto the QA box and dig and find out, sure enough, tomcat is running as a service. The service starts tomcat7.exe //RS//Tomcat7. (Not sure what the tomcat7.exe is.)
So according to the above doc, I set CATALINA_OPTS=-Dnet.sf.ehcache.disabled=true and restart the server.
In the meantime, I've written a handy little servlet that dumps all of the system properties, so I can know immediately what effect my changes have. I run it and it says net.sf.ehcache.disabled=false. Clearly, something is overriding my change.
So I do some reading here: https://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html and set an environment variable to be PR_JvmOptions=-Dnet.sf.ehcache.disabled=true and restart the server. Run my little servlet and:
net.sf.ehcache.disabled=false
So, clearly, something is overriding my settings no matter what I do. The docs say it is ignoring setenv.bat and I don't know where else to look to find this override.

Moving files from Tomcat Linux to another Linux Server

I've taken a job where years ago their webmaster setup an intranet using Tomcat on a linux server. The users can create something in the test environment and then click "make live" and the Linux/Tomcat moves the file to a Linux/live PHP web setup.
I'm clueless how they're moving the files. What would be a common tool to do this in Tomcat and Java?
I realize this is vague, but any help would be appreciated. Let me know what other info would be needed.
Also there is a duplicate MySQL database in both servers. I'm guessing the Tomcat setup is writing duplicate info to both databases, but I don't see how the files are getting moved.
This sounds like the website content is completely stored in the database and written over to the other server.
Theoretically you could also have a rsync shell script and call that from php to actually synchronize files over to the other server.
If the "Make Live" is on click and happens immediately its either a direct db access or some script based synchronization.
If it takes a while it could be a cron-job. Maybe you should just check this anway crontab -l will work.
There are several options, you actually open the *.php which the user can edit the content and see where the make live button brings you e.g. "Post Form to *.php" and than you check what that script is doing or you show us the package (what i would like to see but not suggest if you are working on a companies site).
Get back here with some more information, so i can expand the answer for you. Maybe you should also clarify why you are clueless, state what you have checked already, the info i would require is the actual site which has the make live button on it, it will lead to the next site or a script which will probably show what the site is doing.

Works fine in NetBeans, Have some errors when built

I am in a very very upset situation. My program worked 100% fine when it is in netbeans, but when I build it it has some issues. That is, in my program, there is an one interface and 10 implementation classes. Program calls correct correct implementation class based on how the user save the file (eg: if user save it as game.yellow, it will call "YellowImpl.java", if saved as game.red, then "RedImpl.java" likewise).
But when it is built, it is calling everything fine, instead YellowImpl!! Which means, if the user saves it as game.red, it will call "RedImpl" correctly and same to all other implementations instead YellowImpl. When the user save the file as game.yellow, the program do nothing!!! But this is not happening when it is inside the netbeans! I tried clean and build too, still not good! What is causing this ? Please help!
However, I am unable to provide the code, because it has lot of codings
PS: I am using some libs too
It's difficult to understand exactly what issue you are having with your explaination and no code. However I assume you are having issue with implementation naming conventions.
Perhaps the below link can help.
Java Interfaces/Implementation naming convention
I am agree with #Rhys: it is hard to understand what happens in your application. Just let me give you an advice: do not think (even for 1 second) that there is a bug in java compiler, JVM etc. It is definitely your bug.
How to find it? I suggest you to use remote debugging.
Run your application outside IDE (NetBeans in your case) with enabled remote debugger, connect to it with net beans and debug your application. I believe you will fined the problem within minutes.
How to enable remote debugging? Add the following long string to your java execution command line:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
If something happens in very beginning of your program execution use suspend=y.
Now connect to this application from NetBeans. It is simple, just configure it to port 8000 according to the configuration of your application.
That's it. Good luck.
Thanks a lot for the replies guys. However, I managed to find the issue. That was a simple, capital case!! I have a package called "kolor" and all the implementations are inside that. In my "YelloImpl" class, I have mentioned the package as "Kolor" (Note that "K" is capital). It was fine in netbeans, but outside it wasn't. After clearing this out, everything went fine. Thanks all for the replies again.

Java Code only working in debug mode

I have to make a game in Java for my computer science class. Since I have already wrote a game in Java in my spare time, I decided that I would reuse some of the code. However, after importing my old code I found that it only worked in debug mode. Running it normally would not make the program crash, but many of the in-game features were not working. I think I might have seen a class not found exception once when in debug mode, but it did not show up again. What could possibly be causing this problem? I have already tried re-importing the files. Feel free to ask for any additional information.
For any non-standard class, remove the import statements. Then let the IDE make suggestions. Make sure the suggestions make sense.
When you say "debug mode", do you mean running under the debugger in the IDE, or do you mean when you have logging enabled, or when you insert 'System.out.println' statements?
Hard to say with this amount of info. Maybe you need to clean out the generated class files so that a clean build is made. If it's running on a server, maybe you need to delete and recreate it on the server.

How do you debug a Rails application?

Is it possible to debug a Rails application in a similar way to a Java application - setting breakpoints and stepping into the code?
What are the best tools for this?
I have a hybrid Java/Ruby on Rails application which I can run in Eclipse or Netbeans.
I would like to step into some code in this app and try to figure out the cause of a problem I'm having.
In Eclipse if I set a breakpoint in my blog_controller and then choose the 'Debug' button, it seems to use the ruby-debug-ide gem to execute the code but I get this unhelpful output and no option to step into any source:
Fast Debugger (ruby-debug-ide 0.4.5) listens on localhost:56726
./war/WEB-INF/app/controllers/blog_controller.rb:1
C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby-debug.rb:101:in `debug_load'
C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/lib/ruby-debug.rb:101:in `debug_program'
C:/Ruby18/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.5/bin/rdebug-ide:82
C:/Ruby18/bin/rdebug-ide:19:in `load'
C:/Ruby18/bin/rdebug-ide:19
Uncaught exception: uninitialized constant ApplicationController
I'm not sure if I'm doing something wrong or if this is all I can expect.
The debugger I use the most is the ruby-debug gem, which is a gdb-esque command line debugger. Once you learn a few commands it is very quick and effective, and provides you with some handy features like being able to fire up irb in the context of your program and make on-the-fly changes.
And being command line based it comes in handy when you need to debug a on a remote server.
You can expect more. I have used Aptana's RadRails version of Eclipse to debug a Rails app as you describe--setting breakpoints and stepping through the code.
You may be doing something wrong. It looks as if it is trying to debug an individual controller file, rather than debugging the Rails app. When I try to execute a controller file from the command line, I get a similar message:
C:\workspace\myapp\app\controllers>ruby users_controller.rb
users_controller.rb:1: uninitialized constant ApplicationController (NameError)
In Aptana RadRails, I choose Run > Debug As > Ruby Application to debug the app.
For the vim users I strongly recomend looking into the vim-ruby-debugger, which fits in great with Tim Pope's rails.vim scripts.
It gives you a handy :Rdebugger command, allows you to set breakpoints and open a split window to display variable values.
maybe not relevant, but I wanted to post somewhere: got the error: "undefined method `run_init_script' for Debugger:Module" running the debugger in rails 2.3.2. Did a sudo gem install ruby-debug and the problem went away.
I'd recommend just setting up breakpoints (I actually just puts to console) for 99% of debugging with RoR - this method is simple and usable across any IDE, so you never need to learn how a new debugger works.
Actually, I had the same problem with Aptana. Run > Debug As > Ruby Application just doesn't work. I finally made the debugger work by going to the Servers tab, and then start the server in debug mode. After that, set some breakpoints and trigger the corresponding action. Hope this helps.
Debugging? That's just knowing where to look in the case of Ruby (and by extension, Rails) most of the time.
The problem in this case is that you probably still have your ApplicationController called application.rb where it should be renamed to application_controller.rb.
Debuggin in rails is simple if you know how to read the error stacktrace!! But if you need to explicitly watch out the values during the runtime then u can use the rails breakpointer.Below is the link to how-to on breakpointer ..hope this helps!!!
http://destiney.com/blog/rails-breakpointer
I can't speak for Eclipse (never worked well for me) or Aptana (not tried) but from experience I can say that both NetBeans and RubyMine will do what you want. I both cases you should probably make sure that the ruby-debug-base and ruby-debug-ide gems are up-to-date: RubyMine in particular didn't work for me until that was done.

Categories