Netbeans Debugging Java web application (without main) - java

How can I use the Netbeans visual debugger in a Java Web Application ? I have no main method in my project.
Is it possible?
I'm doing the following steps:
Start Apache Tomcat in Debug Mode.
Right click on Project -> Debug
Web Application is correctly launched. But execution doesn't stop and wait on the selected breakpoints.
I created setenv.bat file in tomcat\bin folder with these commands:
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_92
set JRE_HOME=C:\Program Files (x86)\Java\jre1.8.0_92
CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
In Attach Debugger I specified SocketAttach, dt_socket, Host=localhost, Port=8000

Related

Setting up a local OC4J instance in Intellij

When I am developing I run my application locally on an OC4J instance on my PC and I can start the server from eclipse, deploy the application to OC4J with maven, view it in the browser and debug it in eclipse. I am trying get the same set up in IntelliJ.
The steps to set it up the server in eclipse are:
Preferences > Servers > Runtime Environments -> Add (Oracle > Oracle
OC4j Standalone 10.1.3n)
Open the server configuration/overview window from the servers view
Server Properties > set username, password, port etc
Click "Open Launch Configuration"
Arguments tab > set VM arguments
Classpath tab > User entries shows oc4j.jar ~ C:\oc4j\j2ee\home
Source tab > shows my project directory and a 'Default' directory
JRE tab displays the jdk I am using
When all this is set I can run the server from eclipse and debug my application.
I've done the following in IntelliJ (but it's not working...)
Run > Edit configurations
Add new configuration
Select JSR45 Compatible Server (I've read this is the one to choose for OC4J)
Give it a name, mainly use default values, add OC4J_JVM_ARGS to 'VM Options Variable' box
add -start to VM Options (I've also tried adding all the vm args from eclipse in here)
Startup/connection tab: add C:\oc4j\bin\oc4j.cmd to Startup script box (I can't add the oc4j.jar from C:\oc4j\j2ee\home)
Now when I try to run the server from intellij I get the following output:
C:\oc4j\bin\oc4j.cmd
Usage: oc4j.cmd [Options]
Options:
-start : start OC4J
-shutdown -port -password : stop OC4J
-version : display the version
-help : display this message
Disconnected from server
This seems to be normal and is what happens when you run C:\oc4j\bin\oc4j.cmd, but I don't know what start up script I should be setting in intellij
Can anyone advise? Where should I specify -user and -password in Intellij? Thanks a lot
It seems that the 'Startup script' and'Shutdown script' boxes on the Startup/Connection tab in IntelliJ are not just file inputs, you can also type commands in there. So OC4J can be started by changing my intellij steps as follows:
Run > Edit configurations
Add new configuration
Select JSR45 Compatible Server
give it a name
mainly use default values
add any VM Options you have
add OC4J_JVM_ARGS to 'VM Options Variable' box
Startup/connection tab:
add "C:\oc4j\bin\oc4j.cmd -start" to Startup script box
add "C:\oc4j\bin\oc4j.cmd -shutdown -port=(your port number) -password=(your password)" to Shutdown script box
OC4J can now be started from intellij

Registering Eclipse Headless build as Windows Service

I currently developed an Eclipse application which also has a headless build available to integrate with some other application. We created a .exe for our application. What I need is when the installation of our application is completed the headless build should be register as window service. The headless build is started using a batch file which contains following :
set WORKSPACE=
java -jar plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar -pluginCustomization plugin_customization.ini -application myapplication.app.HEADLESSAPP -data %WORKSPACE% -noExit -isHeadLess
When we run this .bat file it starts our application in Non UI mode.
I tried following things so far:
Tried sc.exe command but this didn't work.
Then I converted my .bat file to .exe and then tried sc.exe(give error 1053) and NSSM(executable path always refer to nssm.exe instead of my application).
So basically I need a way to to register this .bat or .exe file as windows service so that it launch my headless application.
UPDATE :
Tried this :
set SERVICE_NAME=TESTSERVICE
set SERVICE_TITLE="TESTSERVICE"
set ECLIPSE_DIR=%~dp0
"%~dp0TESTSERVICE.exe" install %SERVICE_TITLE% --Startup=auto --StartMode=java --StartImage="%ECLIPSE_DIR%eclipsec.exe" --StartPath="%ECLIPSE_DIR%\" ++StartParams="-noSplash -pluginCustomization plugin_customization.ini -application com.eu.ales.hvac.ipm.headless.app.HEADLESSIPMDT -data \"%ECLIPSE_DIR%workspace\" -configuration \"%ECLIPSE_DIR%configuration\"" --LogPath="%ECLIPSE_DIR%\" --LogLevel="Error" --LogPrefix="service"
but getting this
To run a headless Eclipse RCP application as Windows service I use successfully Apache Commons' prunsrv.exe (download here) for several years.
Step-by-step instruction to run Eclipse Infocenter (which is a headless RCP application and contained in all Eclipse IDE packages) as Windows service:
Preconditions:
A Java JRE or JDK is installed
An Eclipse IDE is installed, e. g. eclipse-SDK-4.7-win32-x86_64.zip
Download commons-daemon-1.0.15-bin-windows.zip from http://www.apache.org/dist/commons/daemon/binaries/windows/
Extract prunsrv.exe from root directory of the downloaded ZIP archive into your Eclipse installation directory
In the Eclipse installation directory create the file install_as_service.bat with following content:
set INFOCENTER_PORT=8088
set INFOCENTER_TITLE="Eclipse Infocenter"
for %%i in ("%~dp0") do (set INFOCENTER_DIR=%%~dpi)
set INFOCENTER_DESCRIPTION=Port: %INFOCENTER_PORT%, Location: %INFOCENTER_DIR%
"%~dp0\prunsrv.exe" install %INFOCENTER_TITLE% --Description="%INFOCENTER_DESCRIPTION% " --Startup=auto --StartMode=exe --StartImage="%INFOCENTER_DIR%eclipsec.exe" --StartPath="%INFOCENTER_DIR%\" ++StartParams="-noSplash#-application#org.eclipse.help.base.infocenterApplication#-data#\"%INFOCENTER_DIR%info_center_workspace\"#-configuration#\"%INFOCENTER_DIR%info_center_configuration\"#-vmargs#-Dserver_port=%INFOCENTER_PORT%#-Xms420m#-Xmx420m#-XX:MaxPermSize=256m" --StopMode=exe --StopTimeout=300 --StopImage="%INFOCENTER_DIR%eclipsec.exe" --StopPath="%INFOCENTER_DIR%\" ++StopParams="-noSplash#-application#org.eclipse.help.base.infocenterApplication#-data#\"%INFOCENTER_DIR%info_center_workspace\"#-configuration#\"%INFOCENTER_DIR%info_center_configuration\""#-command#shutdown --LogPath="%INFOCENTER_DIR%\" --LogLevel="Error" --LogPrefix="service"
Double-click install_as_service.bat
Press Windows+R, enter services.msc and click OK
=> The list of services should contain Eclipse Infocenter
Start the service Eclipse Infocenter
In a web browser open http://localhost:8088/help/index.jsp
=> Eclipse Help should be shown in the web browser (similar to https://help.eclipse.org)
To uninstall the service, first stop the service and then run prunsrv.exe delete "Eclipse Infocenter"

Glassfish not running web application independently of Netbeans

Please see the steps I have followed below:
1) Start the Glassfish server in Netbeans:
2) Run the Netbeans project, which successfully browses to: http://localhost:8080/CRUDWebAppSQL/StudentServlet I am able to use the application.
3) Close Netbeans, which stops Glassfish (in preparation for the next step)
Then I try this:
1) Run the following DOS commands:
cd C:\Program Files\glassfish-4.0\bin
sadmin start-domain domain1
2) Message received saying server has started. Browse to: http://localhost:4848/ and login. Make sure that CRUDWebAppSQL is listed as an app.
3) Browse to: http://localhost:8080/CRUDWebAppSQL/StudentServlet which display a Glassfish 404 error
Why does step three produce a Glassfish 404 error? Does it have something to do with this: Where does glassfish save your class/project after deployment on Windows?
NetBeans is using a different mechanism to deploy your application to support hot deployment in comparison to a manual deployment.
To run the application without NetBeans first build the web application with e.g. with Maven mvn clean install to get the *.war file.
Start the Glassfish application server and either deploy the war file through the web interface or with command line asadmin deploy war-name
By the way I would suggest to update NetBeans to the current 8.2 release and have a look at Payara, which is a patched drop-in replacement for Glassfish: http://www.payara.fish/downloads
Netbeans glassfirsh server combine with Felix platform.
Download GlassFish Server Open Source Edition.
Unzip it and goto bin folder in the unzipped folder.
double click asadmin.bat
type start-domain
in this command you can start glassfirsh server
(you can find more command in google)
open browser and type http://localhost:8080/
click link as
go to the Administration Console.
it view "GlassFish Console".
in here you can deploy your web app.(Extension ".war" file)

debugging java application deployed in tomcat

I have an application that I deployed in tomcat. Later I configured the code as a project in Eclipse. I want to connect to the tomcat via eclipse and debug the application.
Trying to setup a remote debug connection is throwing up errors. Is there any entry that I need to add somewhere in tomcat?
First, you need to run Tomcat in debugging mode. The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not). Find the line near or at the end of the file that contains the start command, and change it to jpda start. This will cause Tomcat to start in debugging mode listening on port 8000.
Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations.... In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list. The important settings to note are the Host and Port fields. The host value must match the hostname of the Tomcat process, and the port should be 8000. You also might need to add entries on the Source tab to ensure that all of the source code is available to step through.
Create a new tomcat server
Create a new dynamic web project
Export war to tomcat server
Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)"
Add breakpoints
Run tomcat in debug mode
Test war in web browser
Edit source path
Debug source code in Tomcat
The war file is available here.
yes, you need to configure tomcat to accept remote debugging connections. There is a FAQ on how to do it with various IDEs.
http://wiki.apache.org/tomcat/FAQ/Developing#Q2
Simply change the line in startup.bat (if you are using Windows)
from:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
to:
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Right Click on the project you want to debug and go to Debug As Menu and in the list click on Debug Configurations.
Then Double click on the Remote Java Application from left menu list. browse for the project u wanna add in then click apply.
Also change the listening port to 7999, then after you started the web app from your localhost click the debug button on the same window. Then any break point's will be hit after that.
Steps to setup the tomcat Debugger with eclipse
Install the following things:
java 1.8+
eclipse EE version
download tomcat 8+
open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)
Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)
Export war (File-> Export-> search war -> select module and choose the path)
Run as -> Run on Server
Start the tomcat Server in Debug or Run Mode
check on localhost:8080
Debug worked for me. I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.
Open tomcat/conf/bin/startup.sh and added below lines
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
In the same file startup.sh, added jpda before start command.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$#"
Restart the tomcat.
In eclipse go to Run>Debug configuration>Remote java application>Add host ip and port(8000) where tomcat is running.
In my case i required to open 8000 through firewall too.
firewall-cmd --zone=public --permanent --add-port=8000/tcp
firewall-cmd --reload
Beside remote debugging, you can debug your app locally within eclipse if you added tomcat in eclipse.
just start server and wright click your app and from debug menu hit debug on server.
If you have multi module maven project, debug on server just shown up for module with war packaging.
If you want debug a class that runs at startup by self, like methods that annotated with #PostConstruct, remember that you should increase server timeout.
To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.

How to debug a JSP tomcat service using eclipse?

I would like to debug my separately running JSP/Struts/Tomcat/Hibernate application stack using the Eclipse IDE debugger. How do I setup the java JVM and eclipse so that I can set breakpoints, monitor variable values, and see the code that is currently executing?
I just Googled it. :)
http://bugs.sakaiproject.org/confluence/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging
Many more on google.
Effectively, set your JPDA settings:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start
Then, in Eclipse, Run->Debug Configurations...->Remote Applications.
Follow these steps:
Add the following arguments to the java command that is used to launch Tomcat (on Windows, I think this is in TOMCAT\bin\catalina.bat)
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
In Eclipse, create a 'Remote Java Application' debug configuration and set the port to 8787 and the host to the name (or IP address) of the machine where Tomcat is running. If Tomcat is running on the same machine as Eclipse, use 'localhost'.
In the 'source' tab of the debug configuration, add any projects that you want to debug into
Start Tomcat
Launch the debug configuration you created in step 2
Eclipse should now stop at any breakpoints that you've set in the projects you added in step 3.
Notes:
You can change the port to any other available port if for some reason you can't use 8787
If you want Tomcat to wait for the remote debugger to start, use 'suspend=n' in the command above to 'suspend=y'
You could do what they suggest, or use this Eclipse plugin, which makes it easier to configure Tomcat to begin with: Eclipse Tomcat Plugin
When launching tomcat via this plugin, it starts in debug mode by default, you must explicitly disable debugging mode if you want it to not allow Eclipse to connect a remote debugger.
For Tomcat 5.5 on Windows:
Edit bin/startup.bat
Find the line that reads:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
Replace it with these lines:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Categories