Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to integrate Jetty with, IntelliJ IDEA, you,need two scripts.

Code Block
borderStylesolid
titleStartJetty.bat

@echo off
setlocal
if not "%JAVA_HOME%" == "" goto JettyAction

:SearchFromRegistry
echo JAVA_HOME environment variable is not set.
echo Searching registry...
for /f "usebackq tokens=3" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit" /s ^2^> null \^\|find "JavaHome"`) do set JAVA_HOME=%%~i
if not "%JAVA_HOME%" == "" goto JettyAction

:NoJava
echo Could not find JDK in your system. Please install JDK
endlocal
exit/b 1

:JettyAction
if not "%CD%\" == "%~dp0" echo Please say 'Y' if prompted for "Terminate batch job (Y/N)?"
rem %~dp0 is current dir in Winodws NT
set curpath=%~dp0
pushd %curpath%
set runcmd=%JAVA_HOME%\bin\java \-showversion \-DSTOP.PORT=8079 \-DSTOP.KEY=secret %VM_DEBUG_VAR% \-jar start.jar %\*
echo "Using " %runcmd%
%runcmd%
popd
endlocal

Code Block
borderStylesolid
titleStopJetty.bat

@echo off
setlocal
if not "%JAVA_HOME%" == "" goto JettyAction

:SearchFromRegistry
echo JAVA_HOME environment variable is not set.
echo Searching registry...
for /f "usebackq tokens=3" %%i in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit" /s ^2^> null \^\|find "JavaHome"`) do set JAVA_HOME=%%~i
if not "%JAVA_HOME%" == "" goto JettyAction

:NoJava
echo Could not find JDK in your system. Please install JDK
endlocal
exit/b 1

:JettyAction
if not "%CD%\" == "%~dp0" echo Please say 'Y' if prompted for "Terminate batch job (Y/N)?"
rem %~dp0 is current dir in Winodws NT
set curpath=%~dp0
pushd %curpath%
set runcmd=%JAVA_HOME%\bin\java \-showversion \-DSTOP.PORT=8079 \-DSTOP.KEY=secret \-jar start.jar \--stop
echo "Using " %runcmd%
%runcmd%
popd
endlocal

Info

These scripts are not named specifically as IntelliJ scripts because they are also general purpose batch files to start and stop and Jetty.

The script works reliably when placed immediately in Jetty dir. The script uses JAVA_HOME environment variable if set. If it,is not set, then the script tries to determine JAVA_HOME from Windows Registry. The script can be run from any location, however the relative paths are computed with respect to Jetty dir. If you are running script from other dir then you should say 'Y' if prompted for "Terminate batch job (Y/N)?". This,situation frequently arise when Ctrl+C is used for terminating a batch program. Otherwise, you will notice that your current directory is still set to Jetty dir. This is generally, a good practice for other Batch programs as well.

...

First of all, you would need to setup Jetty as Application Server in IntelliJ Settings. It's usually Ctrl+Alt+S or File->Settings. Navigate to "Application Servers" option,and add a Generic Server.

Image Added

It is,named,Jetty here and servlet-api-2.5.jar and other jars from,jetty lib dir are attached. You will also notice IntelliJ warning regarding not finding EJB classes. That's ok because Jetty is not an EJB container.

Image Added

To Debug and Run your web app project from IntelliJ, you need to create a Local "JSR45 Compatible Server" configuration under Run-> Edit Configurations menu. Note that IntelliJ only allows you to configure this for each project.

Image Added

I named the Local configuration as "Jetty".
In "Server" tab, select Application Server we just created. Configure port consistent with jetty.xml,or value of jetty.port system property. Specify JSP package as org.apache.jsp. Refer to you webdefault.xml if you have,customized package for JSP generated java classes. Set value of VM options variable VM_DEBUG_VAR. This environment variable is used in Batch Scripts. Note:

Note
titleDon't use VM_OPTS variable name

Due to certain bug in IntelliJ plugin,,if you name,this variable VM_OPTS, it is not passed to Batch Scripts. So avoid using VM_OPTS name,as environment variable. It's quite easy to use this variable as it is used in IntelliJ examples.

http://www.jetbrains.com/idea/docs/help/project/rundebugjsr45.html
You can also check/uncheck Start Browser,depending on what you want.

Image Added

In "Startup/Connection" tab,,you need to select the start and stop script for,running and debugging script.

Image Added

I have also specified JAVA_HOME environment variable in this case. The StartJetty.bat and StopJetty.bat script work for both running and debugging.
IntelliJ passes,debug parameters in form of an environment variable to the script. See the value of VM_DEBUG_VAR created by IntelliJ for Debug mode.

Image Added

Other VM parameters and program arguments can be passed by selecting Image Added icon next to each script.

Image Added

Now create a jsp in your web app and try a breakpoint in a jsp.

...

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery