I'm using Eclipse; when I run my code in debug I get a class not found exception but running it without the debug it works fine.
I see it doesn't find the classes I wrote.
How can I fix this?
Double-check that the Run Configuration in Eclipse has the same classpath set for both (running it normally vs debug).
Eclipse has a lot of settings but I would try checking the following:
Run > Debug Configurations > Java Application > PROJECT_NAME > Classpath
Also, you can check your source under the same location to make sure all of your JAR files have been properly added.
I assume we're looking at a normal Java Application. Eclipse creates Run Configurations for normal execution and Debug Configurations for debug runs. And there's usually no significant difference between a Run and a Debug configuration for the same class.
The easiest way would be to start clean: Navigate to 'Run Configurations...' and delete all 'Java Application' configurations. Then do the same for 'Debug Configurations'. After this is done, start your application once in normal and once in debug mode.
Alternative: switch to a new workspace (File -> Switch workspace), import the project(s) (File -> Import... , make sure to copy content) and run/debug your application.
Check your run/launch configurations. You probably have a different configuration for debug vs run. Chances are that the debug one isn't pointing to the main class of your program.
Just check the debug... option (pull down the debug menu don't click the button, then click debug...) and the first page should have a field for "Main class". Use the same main class as in your run... option.
Related
When I first set up my JDev project, it used the main method from the first class I had created - so when I hit run, it would use that as the starting point.
I then imported my project onto another computer, including a dozen classes, and when I first hit 'run', JDeveloper asked me which 'main' to start from - but I clicked on the wrong one. At the time I just left it, but I now can't find out how to specify the other class as the correct 'starting point'.
Specifically, I want to do this from within JDeveloper so it works when I hit 'run' on the IDE, I don't want to specify it in the command window when running it, etc.
You can define Jdeveloper run target as follow :
Run > Choose active Run configuration > Manage Run configuration
Edit Default run configuration > Browse > Choose your Default run target
every now and then I am launching JUnit tests from within Eclipse by using
Run As > JUnit Plug-in Test
By default Eclipse assumes you are running something which requires a workbench and chooses in the "Main" section of the launch configuration
LaunchConfig > Main > Program To Run > Run an application >
org.eclipse.ui.ide.workbench
I can understand why this is the default, but for me (and for all in our team) this is never ever the case. We always need to run our JUnit Plug-in Tests as
LaunchConfig > Main > Program To Run > Run an application >
[No Application] Headless Mode
How do I change this default behaviour?
I am currently using Eclipse 4.4.
It seems a custom LaunchConfiguration-Extension is a viable solution attempt.
What I did was to create a new, custom LaunchConfiguration-Extension which is 99.999% build on the JUnitLaunchConfiguration. I only had to add a custom
BlaBlaJUnitPluginTestLauncher extends launching.JUnitLaunchConfigurationDelegate
which overrides the
launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
method to adjust the application parameters according to our needs.
BlaBlaJUnitPluginTestTabGroup extends org.eclipse.pde.ui.launcher.JUnitTabGroup
To be able to initialize the LaunchConfig dialog with the default parameter, I had to:
Add a custom BlaBlaPluginJUnitMainTab extends PluginJUnitMainTab
Create a custom JUnitProgramBlock implementation (BlaBlaJUnitProgramBlock)
Creating an instance of BlaBlaJUnitProgramBlock in the BlaBlaJUnitPluginTestTabGroup.BlaBlaPluginJUnitMainTab.createProgramBlock() method
Overriding setDefaults-method (not sure if its really neccessary) in BlaBlaJUnitProgramBlock
Overriding initializeForm-method in the BlaBlaJUnitProgramBlock and adjust parameter there too.
Leading to the following result:
This answer is a near miss:
Try this:
Manually create and configure one "good" launch configuration.
Next time you want to launch a test that doesn't yet have a good launch configuration:
Select the file and invoke Run As > Run Configurations ... (i.e., don't yet select JUnit Plug-in Test!)
In that dialog select a good launch configuration of the same kind, and ...
Then click New Launch Configuration (upper-left corner)
Now the newly created configuration should "inherit" the configured values from the the good configuration.
Truth is:
You can duplicate an existing launch configuration (leaving you to manually select the test to launch)
The Debug team once had plans to support launch configuration templates.
Edit 2018:
Since Eclipse Photon, the Java debugger supports launch configuration prototypes. I just filed Bug 536728 to request this also for test launches. Feel free to chime in (or contribute) on that bug.
if u r looking for only shortcut for convenience then eclipse remembers last execution. After using run as and saving ur run config, just use "Run as" button in toolbar.
besides this eclipse comes with flavour for testers, u can check that out.
Also since you are talking about unit testing see if you can make use of ant build or even better converting to maven based project. Maven has integrated support for testing.
There seems to be a simple and effective heuristic in place, which decides whether or not a JUnit Plug-in Test should be run headlessly or with an application:
Make sure that the plug-in containing your tests has no dependencies on anything org.eclipse.ui.
Without that dependency [No Application - Headless Mode] is selected by default for newly created launch configurations.
With that dependency the default is Run a product, with s.t. like org.eclipse.platform.ide preselected.
I have a Java Maven Project started in Eclipse, worked on it a few days, then imported it in IntelliJ IDEA, again working on it a few days.
The normal Run/Execution in IDEA and via shell does work, but not the Debug.
When I click the Bug Icon for Debug, it opens up URLClassLoader.java file and points on the Line "throw new ClassNotFoundException(name)" and pauses the Debug, if I click Resume Debug, it shows several Classes that do not belong to my project. I can click the Resume Button endless, it shows the same classes, also ClassNotFoundException over and over again in a continuously loop and does not debug my source.
If I click Build -> Rebuild Project it says at the Debug icon
"Hot Swap failed
myClassname: schema change not implemented;
myClassname: Operation not supported by VM"
In the Debug window under Variables it says: "Frame is not available"
The Debug of this project in IntelliJ IDEA did work previously, whats wrong now?
Looks like you have an exception breakpoint on ClassNotFoundException. Please try to open Run | View Breakpoints... and uncheck the breakpoint under "Java Exception Breakpoints".
in my situation, just neglect the evaluate language drop down.
This is really helpful. Go to your breakpoints in debug mode and make sure to deselect all the breakpoints first and then select only the ones in your class.
How do I set the main Java type in Eclipse (latest)?
I have a main client, and then a bunch of unit tests that exercise various code paths and conditions. Normally I'd like to debug or execute the unit tests depending on the feature I'm developing. However, when the boss shows up, I'd like to quickly run my main driver class without hunting and pecking for the .java file, then hitting debug.
Is there an easy way to set/change the main type? How do folks normally handle running unit tests in Eclipse?
Click on the arrow in the run/debug icon and select Organize Favorites at the bottom and set favorites for anything you don't want to fumble around for later.
For unit tests, I just run them like anything else in Eclipse. I also include a test target in my Ant scripts.
For unit tests :
You can make test suite so to bundle them by feature. This way you just need to run the test suite related to your feature.
Having several launch configuration :
Just go Run Configuration... or Debug Configuration ... from Run menu and create the configuration you want. Next time you'll want to Run them go again to that menu select it and click Run/Debug;
To gain time you can go to Keys configuration and set at shortcut to "Run..." or "Debug..." submenu.
Right click on your test folder and "Run as ... -> JUnit test"?
From Run > Run Configuration... Create a new Run Configuration for the type of java application you have and the options let you specify the main class.
And these configurations will be available in the Run As button dropdown.
I have a java class and I need to debug it (put breakpoints and continue using F6). I am using ANT script to init, build, deploy and run the code. I am using:
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="true" debuglevel="lines,vars,source">
..........
</javac>
But when I place the breakpoint in a line in my foo.java class and I run the ant script (the run part, Right Click on run-->Debug As-->Ant Build), Eclipse does not stop at that line of code.
What am I missing out?!
(Wasn't able to comment on the given answer, so have to make another answer)
I realized that when launching Ant from Eclipse, you'll have to add fork="true" to the <java> task. Also, it was first not clear to me how to write nested jvmargs, so here goes an example:
<java classname="..." fork="true">
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432" />
...
</java>
In the <java> ant task you should add two jvm parameters (<jvmarg> IIRC) to turn on debugging:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5432
This will launch the java program with debugging turned on and the program will be ready to accept debugger connections on port 5432. Then you should use your IDE's remote debugging facility and direct it to connect to port 5432.
In Eclipse:
Toolbar > External Tool Configurations... > (select your existing ANT build or create new) > JRE tab
In "VM Arguments" add:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
Again Toolbar > Debug > Debug Configurations... > Remote Java Application > New
Name: Debug Ant
Project: <Select your project where debug files are kept>
Host: localhost
Port: 8787
Now in "External Tool Configurations" launch "ANT Task" (which waits for the Remote Java Application debugger to connect), then launch the "Debug Ant" from the "Debug" toolbar icon.
This is how I got it working for me (Just commenting for future reference).
Link dump ahead :
Debugging ant tasks is not as simple as plain old java debugging.
While you can debug an Ant file adding breakpoints, digging inside the
code of specific custom task will require you to add a remote debugger
in order to be able to "catch" the running process.
I will explain how to do this in Eclipse, altough I recon it can be
achieved with all major java IDEs. First thing is to create a new run
configuration for the ant file where you plan to use your customized
new task. To do so, go to:
Run -> External Tools -> External Tools configuration...
Right click in Ant Build -> New and in the Main tab select your ant
script in Buildfile field. Then go to JRE tab and insert the following
JVM arguments:
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
If you wonder what these arguments mean check this, although a bit
updated (Java 1.5) still works.
Once this is done, you must create a new Debug configuration for a
remote Java application. To do so, navigate to:
Run-> Debug configurations
Drop down the list in the left column and right click in Remote Java
Application -> New. Select the project name in the Project field.
Default values for host and port are okay as long as you used the same
ones for the Ant configuration (JVM arguments).
Everything is ready for the test run! Add breakpoints wherever you
consider necessary. In my case, I added one both in the ant script
that uses the custom ant task as well as in the custom ant task, in
the execute method.
Right click in your ant script or task -> Debug As...-> Ant >Build
first
Now BEFORE calling your custom ant task code, go to Run-> Debug
Configurations and debug your previously created Java Remote
Application config. This will start a separate thread that will debug
your custom ant task code, provided that you included some breakpoints
:) You can see in the following image how in my case, thread stopped
in the execute method of my custom ant task.
After this point, it is up to you to decide what to do next...
This is to help the people who are wondering how to debug the web application that use ant to build and deploy. This is quite frequent in legacy applications. If the project was started as "Dynamic Web Project" as the beginning, following steps and even Ant is not necessary.
Set the break point in your code.
Window -> Show View -> Others -> Servers
Add your server JBoss or Tomcat for example.
Right click on the server and choose 'Debug'.
Make sure that debug="true" is set in ant build file.
set ANT_OPTS=%ANT_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432
in Eclipse
Toolbar >> Run >> Debug Configurations >> + >>
Give the values:
Name: Debug_Ant
Project: active-eclipse-project
Host:localhost
Port:5432
Steps:
1)Configure remote java debugger with local host as name, port address as 8000(or whatever your system's port address will be)
2)Create a batch file and keep that in bin folder of your tomcat(this step is required when we want to debug remotely keeping server/s in same system).
in batch file you should keep this line:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
catalina.bat jpda start
after this keep a break point in your java code, and debug this remote debugger. it will work.
Happy Coding !!
I too faced this problem, I did following steps to resolve.
Put the below lines in ANT file
Go to the debugging configurations->Remote java application-> Create new configuration file with project name,port=5432 and host is localhost and save it.
Now run your build.xml using debugging mode, then you should see in console that "Listening for transport dt_socket at address 5432"
Now run debug configuration file which is you configured. Now your selenium code will run using Debug mode.
Hope this helps.
If you still facing issues, please let me know so that i can help you on that.
Thanks