Hot Swapping With Maven, Jetty and IntelliJ
I’ve always been a bit jealous when it comes to the Play! framework and the great dev mode they have for hot swapping classes at runtime. Jetty has a configuration setting, scanIntervalSeconds, that mimics this when working with a more traditional WAR, but does so by looking for changes to a file and reloading the whole server context.
Fortunately, Jetty also provides the ability to rapidly test code with hot swapping. No more server restarts. The trick to getting hot swapping to work is to attach a remote debugger to your Jetty process. The following instructions outline how to do this in IntelliJ (tested with IDEA 10.5 CE).
Modify your jetty-maven-plugin to ignore the scan interval
- Open your pom and locate the plugins section
- In the configuration element, ensure scanIntervalSeconds is set to 0
plugin> groupId>org.mortbay.jettygroupId> artifactId>jetty-maven-pluginartifactId> . configuration> scanIntervalSeconds>0scanIntervalSeconds> . configuration> plugin>
Create a Maven run configuration for Jetty in IntelliJ
- From IntelliJ, click Run > Edit Configurations
- Click Add New Configuration (the plus sign)
- Choose Maven
- Name it Jetty (or whatever you like)
- Choose the appropriate working directory
- In Goals, enter jetty:run
- Click the Runner tab
- In VM Parameters, enter -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000 . Note: the address here corresponds to the port you will debug with. Using 4000 leaves the more standard 5005 debug port open for other debuggers.
- Click Ok
Create an Application debug configuration
- From IntelliJ, click Run > Edit Configurations
- Click Add New Configuration (the plus sign)
- Choose Remote
- Name it Jetty-Hotswap (or whatever you like)
- In the Port field, enter 4000 . Note: If you modified the address in step 1.8 above, the port should match.
- Click Ok
Setup Reloading Classes After Compilation
- From IntelliJ, open Settings (the wrench icon)
- Navigate to Debugger > HotSwap
- Choose Always for Reload classes after compilation
- Click Ok
Run the Setup
- Run the run target, Jetty
- Run the debug target, Jetty-Hotswap
The setup for hot swapping is done. All you need to do is start changing some code — no server restarts. The annoyance with IntelliJ (as opposed to Eclipse’s autobuild feature) is that it won’t compile classes on save. You will have to compile them yourself.
Bonus: Create a Keymap to Compile
Build > Compile ‘. filename.java’ will compile the one class you modified. ( shift + command + f9 on a Mac by default). To further simplify, I added the keymap ctrl + x to the compile menu option. The keymap may vary from OS to OS, or based on your existing keymaps, so you may have to find a keymap that works best for you.
Как запустить Jetty в Idea 2017.3.3?
Прохожу уроки по Intuit mailru урокам. В курсе запланировано создание игрового приложения, все уроки проводятся в IDE отличной от моей, после прохождения основ представлено первое задание самостоятельной работы — запустить Jetty без подсказок. Самостоятельно разобраться не смог. Подскажите, пожалуйста, по-шагово как прикрутить Jetty в Inteliji IDEA.
Примечание: имею опыт по запуску контейнера сервлетов, знания находятся на уровне: «могу запустить Tomcat и дальше не умею.
- Вопрос задан более трёх лет назад
- 730 просмотров
1 комментарий
Оценить 1 комментарий
Как правильно использовать Attach to process в intellij idea?
Есть проект сервлета, который я запускаю на отладку через jetty.
Есть проект плагина в виде jar. Плагин (класс) загружается через URLClassLoader в сервлете и принимает вызовы из сервлета.
Я хотел бы ловить точки останова в проекте плагина.
Для этого из проекта плагина я подключаюсь через Attach to process к процессу сервлета и выбираю процесс:
При этом в variables я вижу сообщение
Target VM is not paused by breakpoint request. Evaluation of methods is not possible in this mode
При вызове методов плагина из сервлета, в проекте плагина я не ловлю точки останова.
Что я делаю не правильно?
- Вопрос задан более двух лет назад
- 105 просмотров
Intellij IDEA не видит org.eclipse.jetty*
не ресолвится. Просить открыть на проксе что конкретно? Я не могу обьяснить админу, чего не хватает. Помогите советом!
achechet
01.09.17 16:32:17 MSK
Я, бы посоветовал использовать Leafpad, там нет таких проблемм.
anonymous
( 01.09.17 16:55:39 MSK )
А с консоли-то находит? Если это у тебя mvn или что другое
dave ★★★★★
( 01.09.17 16:57:02 MSK )
либо клади в lib, либо используй Maven
bvn13 ★★★★★
( 01.09.17 16:58:32 MSK )
Откуда не подхватывает? Gradle? Maven?
xcariba ★★
( 01.09.17 16:58:56 MSK )
Опыта у меня маловато, я разбираю курс по программированию веб сервисов и уходить в сторону от идеи не получиться. Если я ручками качаю и в либ кладу и потом в проджект сеттингах добавляю то так получится. Но хочется чтоб идея занялась этим вопросом, да и не все библиотеки понятно откуда качать.