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.
Related
Any idea why this is happening? I am using OSX Maverick and Eclipse.
I have no Add method used in my program and I don't see the reason it's nagging about it.
You could try to restart the Eclipse. I had this problem too and it works.
"The debugger issue is a restriction of the Eclipse hot-swap JPDA/JVM mechanism. Presently there is a limitation to how much a class may be modified and still be replaceable through the JPDA. My understanding is that can the shape of a class may not be modified, i.e., add/remove fields or methods. The "may be out of sync" warning indicates the change to a class within Eclipse has not been replaced in the server's JVM. To resolve this problem you must restart your server. In the near future we are planning to add an application RELOAD feature that we believe will workaround this problem. " ------myEclipseide.com
http://www.myeclipseide.com/PNphpBB2-viewtopic-t-583-highlight-shape.html
I think that JVM run by Eclipse is not the same as the JVM running your Java application.
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.
I am building an application in Java using Netbeans IDE. I am trying to debug some errors in my code. But even when I modify messages passed in the log statements, I do not see a corresponding change in the logged messages. This implies that when execute the code, it probably runs an older version of code & prints the old version of log messages as well.
What is the cause of this error ? & how should I rectify this ?
Thanks for helping..
I had that same problem...closing and reopening netbeans fixed it for me...
By saving the code. I assume, you are have compile-on-save enabled. If not then you have to build it before running it.
Yes you need to enable build-on-save, otherwise GlassFish wouldn't be able to show you the changes, because the new changes have never been deployed. Sometimes, deploying on save bothers a lot. So, what I do is, I don't enable build-on-save and work with tests and thereby run my tests to see the result of the change. When everything seems fine, then I build the app and deploy it on the server for further verifications.
Compile on save must be set.
See the properties of your project.
(Right click, select properties, then select compile).
Another possibility is that you have to redeploy
your project. In such a case I would recommend to
take a look at jRebel.
I'm working on a very big java/servlets/web project and i find it hard finding which classes and and methods is being called. sometimes it takes hours to find the right class. if there an application or plugin or technique that helps a little? im using eclipse.
edit: I'm using apache and tomcat
Regarding your comment to Bozhos answer: use a profiler on your server instance. You start profiling right before you click on a link in your client application ("the browser") and stop right after you have the correct response. Then just examine the profiler logs/views to find out, what actually happend on the server.
The Eclipse Test & Performance Tools Platform Project is worth a try.
CTRL + ALT + H, or right-click > open call hierarchy (when on a method declaration) will give you all callers, with their callers, and so on. You can also reverse the hierarchy
Right click > references > project will give you where a given class is used.
From your comment on Bhozo's answer I conclude that you do NOT mean at development time, but at runtime.
I suggest you connect a debugger to your application and pause it. You can then inspect the callstack at that time, which will usually give you an idea where to look.
To do that, run your java app with the following settings:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
Then in eclipse, add a debug configuration for 'remote' to port 8787 and execute it. Your debugger is now linked to your application. Put eclipse into the debug perspective.
Now click a link in your application, and immediately click the pause button in the debugger. You can now see the callstack. Usually, once you have a clue, you can quickly find good spots to put breakpoints. But this technique helps you get a clue :)
You might want to consider the use of AOP to add a tracing/logging aspect to certain parts of your code. This way you don't have to update your code and can simply write an aspect that logs a line for every method that is called with in example the name of the method, the class and the parameters. This aspect can of course be 'turned off' when building your production version to prevent the trace logging on production machines. If you're familiar with AOP, you can easily tweak the aspect and the pointcuts a bit to for instance only log calls to certain methods in your controller classes or something like that.
If you need more information on this solution, feel free to comment on this answer requesting more specific information or simply google for AOP and logging.
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.