When developing Maven web applications I usually resort the the jetty-maven-plugin to quickly launch my application for local testing and debugging. Using the launch with m2eclipse has the drawback of not properly including all sources for debugging, even though they are downloaded by Maven ( see Source lookup does not seem to work ).
What is the preferred way to debug Maven web applications in Eclipse? I'd especially appreciate configurations which work with the gwt-maven-plugin.
My preferred way to develop web applications with m2eclipse is to... not use it. Instead, I use the approach described in Debugging with the Maven Jetty Plugin in Eclipse that I'm quoting below:
Step 1
Go to the Run/External Tools/External
Tools ..." menu item on the "Run" menu
bar. Select "Program" and click the
"New" button. On the "Main" tab, fill
in the "Location:" as the full path to
your "mvn" executable. For the
"Working Directory:" select the
workspace that matches your webapp.
For "Arguments:" add jetty:run.
Move to the "Environment" tab and
click the "New" button to add a new
variable named MAVEN_OPTS with the
value:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y
If you supply suspend=n instead of
suspend=y you can start immediately
without running the debugger and
launch the debugger at anytime you
really wish to debug.
Step 2
Then, pull up the "Run/Debug/Debug
..." menu item and select "Remote Java
Application" and click the "New"
button. Fill in the dialog by
selecting your webapp project for the
"Project:" field, and ensure you are
using the same port number as you
specified in the address= property
above.
Now all you need to do is to
Run/External Tools and select the name
of the maven tool setup you created in
step 1 to start the plugin and then
Run/Debug and select the name of the
debug setup you setup in step2.
From instructions provided by
Rolf Strijdhorst on the Maven mailing
list
Stopping Jetty
In order to stop the jetty server the
"Allow termination of remote VM"
should be checked in debug dialog in
Step 2. When you have the jetty server
running and the debugger connected you
can switch to the debug perspective.
In the debug view, right click on the
Java HotSpot(TM) Client
VM[localhost:4000] and chose
terminate. This will stop the debugger
and the jetty server.
Try to avoid writing code which needs a container of some kind to debug. Always write code that can run independently and wrap it in a very thin layer for deployment (thin layer -> few lines of code -> few bugs).
If you really must, try MockRunner to emulate the app server.
Other than that, you can manually add the sources in the project properties.
Related
I'm migrating from Eclipse IDE (+ VSCode for coding Java servlets and HTML/CSS/JS webpages, respectively) to only Visual Studio Code for its lightweight.
I have several Java extensions installed for VSCode:
Language Support for Java(TM) by Red Hat
Tomcat for Java
Debugger for Java
Eclipse has a series of settings for hot reloading:
- Automatically publish when resources change
- Refresh using native hooks or polling
while VSCode doesn't seem to have any for me.
A few things I've try to reload my Java and web code:
Restart Tomcat server
Delete and re-adding Tomcat server
Delete and regenerate .war package (not sure if this does anything, it can run well without a .war package)
Good news...
It works automatically now. With Tomcat for Java Extension (And the rest of the Java Extension Pack):
https://marketplace.visualstudio.com/items?itemName=adashen.vscode-tomcat
Just make sure your settings are like this (search for "java.autobuild" to get those two in the first results):
Very important is, that you wont see any logs in the console on the HCR (Hot Code Replacement) like it happens in Eclipse ... but you in fact will see the replaced code behavior. Just debug over the piece of code you changed, and you will see it in fact changed in the running server.
UPDATE: I've found it works better with the 'manual'(default) setting. Just clicking once in the lightning icon. (Testing in Ubuntu 18.04 LTS)
[I say it works better because if I added lines to a Class' code with the 'auto' setting it will not add that code ... only if I change code in the existing lines. But with the manual setting I just save the file, and then click the lightning icon wait ~3 seconds myself and debug over the new code ... and everything goes well!!
... This solves my coding needs(lightweight Editor/IDE with Hot-Code-Replacement in Tomcat)]
Enjoy !
This article may be helpful, I migrate from other IDE to Vscode.
According to the article, if you install Debugger for Java, it enabled Hot code replacement(HCR) and then :
You can start a debugging session and change a Java file in your development environment, and the debugger will replace the code in the JVM running your code.
Hot code replacement for java comes to visual studio code
Install “Tomcat for java” extension in VScode.
Configure the Path of Tomcat in the above extension.
Now you should be able to run tomcat in usual build -> deploy mode. Now install DCEVM, By using “java -jar installer-light.jar”. (Select “Install DCEVM as altjvm”)
Place HotSwap Agent Jar in directory of your choice.
Now In VScode right-click the Tomcat server you have created. (The one from Step 3 ) And select “Customise JVM Options”.
In the file opened, Place “-XXaltjvm=dcevm
-javaagent:/[your_directory]/hotswap-agent-1.3.1-SNAPSHOT.jar” Now Right-click the tomcat server in VScode and select “Debug WAR package”, And select the WAR file.
If everything goes well, The WAR will be start in TOMCAT in debug mode with text “HOTSWAP AGENT” in the log.
Now your every save to your file will trigger Hot Reloading.
https://medium.com/#manoj_makkuboy/hot-reload-java-8-tomcat-server-in-vscode-ba6233d632e?
Wasnt able to solve the problems in this screen.
http://s8.postimage.org/n5osf76ed/qestions.jpg
All the code worked a month ago.
What have I changed: I have a different version of eclipse (now: Eclipse IDE for Java Developers 1.5.1.20120920-0737, don't know what the previous one was).
Messed with environment variable. Since this does not effect the ot
Please help.
Try this solution mentioned in this discussion.
I just ran into this problem using standard (not Stanford) Eclipse.
By now this is probably moot for you, but I'll post my solution for
future travelers.
The launch configurations for Assignment 1 default to Applet, so the
containing Karel application isn't launched. To solve this, create
and use new Application launch configurations for each file.
If you already tried to run some of the files, delete the Applet
configs created so you can reuse the names:
Open the project properties (e.g. right click on Assignment 1 and select Properties).
Select Run/Debug Configurations.
Select and Delete each configuration.
Click OK.
May the Force be with you.
Create Application configs:
Right click on java file (e.g. CollectNewspaperKarel.java) and select Run As > Run Configurations...
Select Java Application in the left pane.
Click New Launch Configuration (the icon of a document with a +).
Type a name for the configuration and set its Main class to the associated file (e.g. CollectNewspaperKarel).
Click Apply then Run. (This should run correctly and create a useful entry in the Run History.)
Eclipse will still try to default to Applet, so you will henceforth
need to launch these configurations from the Run History (either from
the Run menu or the pull down on the run button). If you accidentally
launch as default, it will add a useless Applet configuration to the
Run History (e.g. CollectNewspaperKarel (1) ). You can delete this
from the Run Configurations dialog to keep the Run History tidy.
The eclipse used in CS106A is customized for stanford and for "karel the robot" :)
Just download and install it again and things should work just fine.
This may well prove to be a simple config change, but I can't seem to find an obvious setting to solve the following problem:
I have a Vaadin project in Eclipse, which is configured to be debugged with Tomcat v6. If I select the top of the project in the project explorer and hit debug, the eclipse browser launches and my web app opens with the following url:
http://localhost:8080/MyVaadinProject/ THIS WORKS
However, if I'm currently looking at a java file (say Myproject.java), Eclipse tries to open the java file at this url:
http://localhost:8080/MyVaadinProject/WEB-INF/classes/com/example/myproject/Myproject.java
Of course, that produces a 404.
Having to deselect/close my java files every time I want to debug is quite tedious. Is there some way to prevent this behaviour in eclipse?
I am on OSX Lion, Eclipse version 3.7.2.
Thanks!
When running the project, instead of highlighting the class file in the Project Explorer, highlight the very base of the project before running.
This is what we want to run anyway, not the class file itself.
Go to
Windows -> Preferences -> Run/Debug -> Launching
There, at the bottom, select "Always launch the previously launched application".
Now you just have to click your project name in the package explorer and do a Run As -> Run on Server once.
After that launch, you will just need to hit the Run Button and your application should always start the way it should be.
I am writing an Android application using Eclipse. When I click on the project in the left tree view and then click debug, the IDE builds an APK and installs in the emulator / device as expected.
However, if I'm editing a file and forget to first click on the project before attempting to debug, the IDE thinks I want to debug that specific Java file. This is NOT what I want to do, I would like it to build and emulate / install on device as usual.
Is there any way to change this behavior in Eclipse?
In eclipse, you can set in workspace preferences / run-debug / launching to always launch the previously launched application (until you explicitly choose an other application: then it will be the last that will be launched).
This way, no matter where you press (ctrl)F11 or click the debug/run button, the launch configuration you used the last time will be called again.
You will still be able to launch different applications of course, by explicitly calling their launchers (the way you debug now).
The procedure you are using (clicking on the project and selecting Debug as => Android Application is OK, for the first debug session (resp. Run as, non debug).
If you want to debug the app again (regardless of what is selected in the left hand side navigator), you should just click on the Green Run circular icon (or rather on the small > sign on its right side if you want to select a different run configuration) or the little bug on its left (for debug).
If you click on one of the > you will select on of the 8 last run/debugged app. If you are sure that the last one is the one you want to run again, then just press one of these two icons (bug for debug, green arrow for run) instead of the arrows.
When you click on the project and select Debug as what you actually do is configure a default run configuration for this app or class that can be later tweaked through the Run/debug Configurations... to better suit your customisation needs. If you click again, eclipse will detect that it has already generated a default configuration (and will not create a new identical one). Alternately you can directly create your new Run/Debug config directly through the Run/debug Configurations... sub menu.
Since the ADT plugin shipped by Google does not include a Run as... Android Application submenu when you click a java class under an android project, the default launch configuration is the java application or the server application (static main method absent).
Update
To clarify things a bit. What you ask (running your android app whilst having the java class selected in the package explorer is possible). What happens when you press the 'small bug' icon does not depend on what is selected in any navigator.
The "default launch configuration" is poorly phrased.
Let me describe what happens in more detail. When you right-click on a java class say in the package explorer (or the project explorer for Java EE version) eclipse (the navigator) calls all contributions (plugins) having registered a handler for that event and lists possible candidates in a sub menu.
In a standard Java EE eclipse installation you will see at least the run on server option and if the class has a main static method with string array arguments, you will also have a the runs as ... java application option. In both cases, eclipse will generate for you a "launch configuration". These launch configurations (both debug and non debug) are all available in the launcher dialog boxes (accessible via the icons described above). They have a lot of different configuration options depending on their nature (for instance whether you debug on a server or a simple java app or an applet). What I termed the "default configuration" is that for each of this launch configuration categories, eclipse will leave these options empty.
So the first time, you will select the Android project and select the run as... Android application option. This will create a default configuration. In ADT's case, the default configuration will also probably select a default ADV and launch it (if it's not already launched). And on subsequent occasions, it will be enough to press the run or debug icon to redeploy your app back to your ADV and this will happen regardless of what is selected in the navigator.
I'm currently writing a GWT application through Eclipse. Eclipse is used for development but I use the m2eclipse plugin and a Maven pom.xml with the GWT plugin to build & run it.
When I need to debug the app I must:
Invoke "Run As ..." on a Maven project (via m2eclipse) "war:exploded gwt:debug". This launches GWT's app server and waits for a remote debug connection on port 3408. The need to wait for the WAR to be exploded means it could be a minute for this to happen.
Invoke "Debug As..." a Remote Java Application to connect to the server.
I've already added both targets to favourites to lock them into the drop down but it's still a pain.
I'd like to launch them both in sequence from a single click rather than two discrete actions.
Is there any way in Eclipse to achieve this?
Try this plugin. http://marketplace.eclipse.org/content/escripts
You can define scripts of Eclipse actions easily. You create a script of starting the 2 debug session, then run with one click or shortcut.
EDIT:
The plugin was moved and is now called EASE.
https://eclipse.org/ease/
"Launch Groups" are part of the CDT. Officially supported, easy to install.
See https://stackoverflow.com/a/11905444/518491
Why are you launching like this? Can't you just launch it by GWT plugin? Go to Run Configurations -> Web Application (the blue circle with "g" inside) and create new Run Configuration.
In it, in Main tab, enter (or select) your project, and enter com.google.gwt.dev.DevMode in Main class.
In Arguments enter -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -port 8888 -war path_to_your_dir_with_WEB-INF_directory com.package.your.Module