Debugging JNLP started application - java

I created a Java desktop-application (using Swing) and am now trying to make it work by starting it from the net using JNLP. The application works fine when I start it from the terminal, but as soon as I launch it from JNLP, it does not close. I have to manually kill the process every time.
I read that there might be a problem if my JFrame uses DISPOSE_ON_CLOSE as the default close-operation, but it doesn't. It uses DO_NOTHING_ON_CLOSE (implicitly). Also, I'm explicitly calling System.exit(0) after releasing all my objects:
f = new JFrame("Pacman");
f.addWindowListener(new WindowAdapter() {
#Override
public void windowClosing(WindowEvent e) {
// Terminate the Game-loop:
GameLoop.INSTANCE.stopLoop();
// Close the application:
System.exit(0);
}
});
I guess that there might be an exception thrown when I close the application, but I can't find a way to get the console-output (e.g. the Stack-Trace) of a running application started with JNLP. Here's what I tried:
Start javaws with the debugging parameters and connect with jconsole (works but I can't find any exception- or console-ouput).
Start javaws with the debugging parameters and attach IntelliJ debugger to it (also works but does not give me any output)
So, how can I start the application with JNLP and get the output (written to the default out- and error-streams), as if I would do with a normal desktop application?

Solution #1 - Enable Java Console, and look for exceptions.
You can do it via Java Control Panel. Switch to Advanced tab, and in the Java Console make sure Show console is selected.
Then, run your application and monitor the console for exceptions. Fix the exception.
Solution #2 - Debug your running application (properly).
Start the Web Start app like this (for Java 1.6 and newer):
javaws -verbose -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123 http://myserver.com/path/to/myapp.jnlp
If using earlier java versions (1.4.2, 1.5) set the environment variable, like this:
set JAVAWS_VM_ARGS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123"
and run the app via:
javaws http://myserver.com/path/to/myapp.jnlp
When the app runs:
Attach a debugger (Eclipse will do - use Run => Debug Configurations => Remote Java Application, and in Connection Properties panel enter the port passed in the parameters to javaws (in this case: 8123).
Set a breakpoint inside your windowClosing method.
Try to close your application - Eclipse should break the execution on your breakpoint
Step into the GameLoop.INSTANCE.stopLoop() method to see where/when it hangs.
Don't expect to see a solutions in the console, just step through the code with a debugger - if the application hangs, it will show you where.

There are times when even the console doesn't show anything, for example when there is a problem with the TLS/SSL handshake (i.e. a close_notify or handshake_failure). In these cases you need to do the following:
Enable the Java logs and tracing in the Java Control Panel > Advanced.
Enable parameters for debugging Java & launching the JNLP, there are two ways you can do it:
2.a. Download the JNLP file and execute it from command line (the SET command is not required in this particular case).
set JAVA_TOOL_OPTIONS=-Djavax.net.debug=all
javaws -wait jnlp.jnlp
2.b. Add arguments (i.e. -Djavax.net.debug=all) for the JVM in the Java Control Panel > Java > View (this is not required in this particular), and launch the JNLP file from browser:
The logs and traces are located in the log directory from the Java Deployment Home from where I paste these locations:
a. Windows XP: %HOME%\Application Data\Sun\Java\Deployment
b. Windows 7/Vista: %APPDATA%\..\LocalLow\Sun\Java\Deployment
c. Linux/Solaris: %HOME%/.java/deployment

This answer is an alternative to npe answer to enable the remote debug (Windows).
Go to Control Panel;
Click on Java, to open Java Control Panel;
Inside of Java Control Panel, go to Java tab, and click "View";
This will open a window with installed java versions. On runtime parameters put "-Xdebug -Xrunjdwp:transport=dt_socket,address=8123,server=y,suspend=n" (if you want to debug when application is starting, change to "suspend" to "y", that will make the application stop until an editor connect remotely);
Afer that, configure you editor to debug remotely to the configured port (localhost:8123 in this case).

Related

JxBrowser with Java Swing (IntelliJ plugin) - "Received signal 10 BUS_ADRERR"

I'm writing an IntelliJ plugin, and attempting to integrate JxBrowser into the plugin's tool window via Java Swing.
I'm using the toolWindow extension to keep the tool window integration simple.
plugin.xml
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="pluginid" anchor="right" factoryClass="com.solutionloft.codeclippy.MainWindowFactory" />
</extensions>
And so my main factory class looks like this:
public class MainWindowFactory implements ToolWindowFactory {
#Override
public void createToolWindowContent(#NotNull Project project, #NotNull ToolWindow toolWindow) {
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
Content content = toolWindow.getContentManager().getFactory().createContent(view, "", false);
toolWindow.getContentManager().addContent(content);
browser.loadHTML("<html><body><h1>Hello World!</h1></body></html>");
}
}
This appears to work when I run the plugin locally initially (the tool window comes up, and I can see Hello World), but if I terminate the process and then try to run it again, I run into this error:
Received signal 10 BUS_ADRERR 000103bc3000
[0x00017cd9540c]
[0x00017cd95301]
[0x7fff572eef5a]
[0x7fbe7e9f5000]
[end of stack trace]
Process finished with exit code 138 (interrupted by signal 10: SIGBUS)
Am I missing some kind of cleanup step? I'm not sure what could still be running - the only workaround I've found at this point is to do a full computer restart, so I guess some process must be still running that's causing it to conflict. What's the proper way to clean up? Does it have anything to do with browser.dispose()? I haven't had much luck finding documentation on when .dispose() would be appropriate / if it's needed.
I'm using:
* macOS High Sierra
* Java 1.8.0_151 as my JDK
* PyCharm Ultimate as my JRE
Thanks!
Update: Noticed if I kill this process /System/Library/Frameworks/LocalAuthentication.framework/Support/coreauthd, the problem goes away for the next few runs. But sometimes this process doesn't exist and killing a still-running java process is the fix... odd.
According to TeamDev support, the solution is to set the system property jxbrowser.ipc.external=true. Calling System.setProperty("jxbrowser.ipc.external", "true") before you create your browser instance should do the trick. The catch is that the JxBrowser will run in lightweight mode.
You may also ensure that you're properly disposing all browser instances via browser.dispose() and the Chromium engine via BrowserCore.shutdown().
According to the article, all browser instances should disposed when you don't need them. Please try disposing all browser instances before closing your application.

Websphere works when run but fails when debug

I'm using Intellij with WebSphere 8. When I run from within IDE the server works normally. When I try to run it in debug mode however, it fails with the following error:
C:\IBM\WebSphere\AppServer\profiles\AppSrv01\bin\generated_websphere_server_start_script.cmd
C:\IBM\WebSphere\AppServer\java\bin\java -Dfile.encoding=windows-1252 -classpath "C:\IBM\WebSphere\AppServer\runtimes\com.ibm.ws.admin.client_8.5.0.jar;C:\IBM\WebSphere\AppServer\plugins\com.ibm.ws.security.crypto.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.3\plugins\webSphereIntegration\lib\webSphereIntegration.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.3\plugins\JavaEE\lib\javaee-impl.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.3\lib\openapi.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.3\plugins\webSphereIntegration\lib\specifics\webSphereClientImpl.jar" com.intellij.javaee.oss.process.JavaeeProcess 62847 com.intellij.j2ee.webSphere.agent.WebSphereAgent
Error: JDWP agent already loaded - please check java command line options
[2014-08-11 01:58:59,248] Artifact x.ear: Server is not connected. Deploy is not available.
JVMJ9TI064E Agent initialization function Agent_OnLoad failed for library jdwp, return code -1
Detected server admin port: 8880
JVMJ9VM015W Initialization error for library j9jvmti26(-3): JVMJ9VM009E J9VMDllMain failed
Detected server http port: 9080
Disconnected from server
I tried almost everything I have no idea what the problem is. I did google it for several hours with no luck.
Do anyone know what this all is about and how can it be fixed?
Here is my server configuration:
Solution 1
unchecked the Pass environment variables check box and restart the server in debug mode. it should work properly.
Run --> Edit Configuration --> websphere server --> Startup/Conections tab
select debug, you will see the Pass environment variables check box. it need to be unchecked for debug to work.
Solution 2
if debug mode of websphere is working in eclipse and not working in intellij that reason i found out is debugging serverice on the websphere is already started and intellij is again trying to start the debggin service. so stop the service from websphere console (Servers > Server Types > WebSphere application servers > [serverName] > Debugging Service) and all the default configurations in intellij should work.
I had the same problem. Finally I figure it out. I hope this solution helps. I'm using Intellij idea 2019.1.3.. and WebSphere 8.5.5.13
check WebSphere start server script find debug env variable name (in my script (WebSphere\AppServer\bin\startServer.bat)
WAS_DEBUG)
add same debug option name to intelliJ IDEA
run- debug configuration environment tab.
Since default env variable is debug and cannot be overridden
check pass env variables
add WAS_DEBUG option as I did
or you can update WAS_DEBUG as DEBUG (same as default in IntelliJ) in server startup.bat script.
Both should work.
Pretty old, but i was able to experience too!
They will try to fix this now in: https://youtrack.jetbrains.com/issue/IDEA-193580
firstly, sorry if the translation is not good, I am Brazilian and I would like to share the solution I made.
First: Locate the file "startServer.bat in "WebSphere\AppServer\bin" and open it with any text editor.
Second: Search for the second incidence of the word "WAS_DEBUG" and replace it with "DEBUG", as shown in the image...
Third: In Intellij, go to the server settings and in the "Startup/Connection" tab, select debug.
Fourth: Now uncheck the "use default" checkbox in "Startup script" and point to the location of the "startServer.bat" file in the webSphere directory.
Fifth: Right on the left side of the checkbox, there is an option to enter a parameter. Click and a "Program Arguments" field will appear. Enter the server name, in my case it was "server1".
Okay, now just test
enter image description here
enter image description here

JAVA EE 7 First cup tutorial, can't install Glassfish 4 update center

Well I was trying to follow the first cup tutorial, but I'm stuck with a Glassfish error.
I'm supposed to this:
1.2.4 Getting the Latest Updates to the Tutorial
Check for any updates to this tutorial by using the Update Center
included with the Java EE 7 SDK.
1.2.4.1 Update the Tutorial Through the Update Center Open the Update Center and check for any updates to the tutorial.
In NetBeans IDE, select the Services tab and expand the Servers node.
Right-click the GlassFish Server instance and select View Update
Center to display the Update Tool. In the tree, select Available
Updates to display a list of updated packages. Look for updates to the
First Cup for Java EE 7 (javaee-firstcup-tutorial) package. If there
is an updated version of First Cup, select First Cup 7.0 for Java EE 7
(javaee-firstcup-tutorial) and click Install.
The thing is, when I try to open the Update Center, this is what I get:
The software needed for this command (updatetool) is not installed.
If you choose to install Update Tool, your system will be automatically
configured to periodically check for software updates. If you would like
to configure the tool to not check for updates, you can override the
default behavior via the tool's Preferences facility.
Exception in thread "main" java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:658)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at com.sun.pkg.client.Image.checkRepositoryConnection(Image.java:1225)
at com.sun.pkg.client.Catalog.refresh(Catalog.java:132)
at com.sun.pkg.client.Image.refreshCatalogs(Image.java:1627)
at com.sun.pkg.client.Client.main(Client.java:109)
When this tool interacts with package repositories, some system information
such as your system's IP address and operating system type and version
is sent to the repository server. For more information please see:
http://wikis.oracle.com/display/updatecenter/UsageMetricsUC2
Once installation is complete you may re-run this command.
Would you like to install Update Tool now (y/n):
C:\Program Files\glassfish-4.0>"C:\Program Files\Java\jdk1.7.0_40\bin\java" -Dimage.path="C:\Program Files\glassfish-4.0\bin\\.." -jar "C:\Program Files\glassfish-4.0\bin\\..\pkg/lib/pkg-client.jar" refresh
C:\Program Files\glassfish-4.0>"C:\Program Files\Java\jdk1.7.0_40\bin\java" -Dimage.path="C:\Program Files\glassfish-4.0\bin\\.." -jar "C:\Program Files\glassfish-4.0\bin\\..\pkg/lib/pkg-bootstrap.jar" "C:\Users\Fabio\AppData\Local\Temp\pkg-bootstrap11073.props"
Proxy: Using system proxy settings.
Input/output error: Connection reset
Could not download application packages. This could be because:
- a proxy server is needed to access the internet. Please ensure that
the system proxy server settings in your Internet Options control panel
(under Connections:LAN Settings) are correct, or set the HTTP_PROXY
environment variable to the full URL of the proxy server.
- the package server or network connection is slow.
If you are getting time out errors you can try setting the
PKG_CLIENT_CONNECT_TIMEOUT and PKG_CLIENT_READ_TIMEOUT
environment variables and try again. For example to increase
the timeouts to 300 seconds set them to 300
- the package server is down or otherwise inaccessible or it is
generating invalid data. Please contact the provider of the package
server.
This may be a problem with the slow GlassFish update server. Here are some steps you can try:
You should retry first to see if the error occurs again. You can start a cmd, navigate to the \glassfish\bin directory and run updatetool.bat so you can see the output which is printed after the one you posted.
If you are behind a proxy you should make sure it is setup correctly in the system settings.
You can also try to install the updates through the GlassFish admin console. Start your GlassFish instance and navigate to http:\\localhost:4848. On the bottom of the left menu click on Updatetool. There you can choose and install the desired updates.
Another option is to change the timeouts of the pkg tool. To set the timeout to 300 seconds do the following in a cmd (on Windows):
set PKG_CLIENT_CONNECT_TIMEOUT=300
set PKG_CLIENT_READ_TIMEOUT=300
Your last (ok, there may be other ones) option is to just skip the update process and do the tutorial with the current version. It should work anyway and I can see in my GlassFish update center that there is only an update for the tutorial documentation at the moment.
Just set this line into cmd (like administrator):
set PKG_CLIENT_CONNECT_TIMEOUT=300
set PKG_CLIENT_READ_TIMEOUT=300
Maybe the firstcup example is already existed in the install directory. Try to find it in the directory_install_glassfish/glassfish4/docs. The mine contain even javaee-tutorial and firstcup. For the next part, you maybe continue after guide in firstcup.pdf with the part of : Creating Your First Java by create archetype of java project. Good luck !
For the lazy of you the pkg Unix command is:
export PKG_CLIENT_CONNECT_TIMEOUT=300
export PKG_CLIENT_READ_TIMEOUT=300
After being stuck for a while on the installation of GlassFish update server from Netbeans (in my company network, proxy issues), I got it this way:
- Advanced System Settings > System Properties window > Advanced tab, New System Variable: http_proxy, http://username:password#your_proxy:your_port
- Netbeans (running as admin just in case), Services > Server > Glassfish Server > Right button View Domain Update Center, then install
It worked for me, Hope it helps!

Debugging JNLP Application

I want to debug a JNLP application. I am using the below to launch it.
javaws -verbose -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8989 myjnlp.jnlp
I think due to a "double launch" described here, a new VM is launched, which is not taking my debug parameters.
I am able to connect to the first VM(since its in suspend=y), but within seconds that application ends, and a new instance of java is launched and its not in debug.
This is what i see in the console (personal info removed with ...)
*Could not launch from cache. Will try online mode. [Some of required resources are not cached.]
Creating temporary directory: C:\DOCUME~1...\LOCALS~1\Temp\FrontendApplication-8.2.1.0-...
Creating installation directory: C:\DOCUME~1...\LOCALS~1\Temp\FrontendApplication-8.2.1.0-...\install
localVersion: 20120409141901452
appVersion: 20120409141901452
New version available: false
Downloading archives...
pluginDir is C:\DOCUME~1...\LOCALS~1\Temp\FrontendApplication-8.2.1.0-...\install\plugins
Framework: C:\DOCUME~1...\LOCALS~1\Temp\FrontendApplication-8.2.1.0-...\install\plugins\org.eclipse.osgi_3.6.2.R36x_v20110210.jar
Invoking starter...*

Remote debugging using Eclipse - How to set breakpoints?

I asked this question about how to debug server side applications and I think I was looking for Java remote Debugging.
I have configured my server side startup script:
JAVA_OPTS="-Xmx2G -server -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n"
By this, I assume the remote java app should be available on localhost:1044 (try it first using localhost)
But, what do I do next? I have configured the debug options to the class to be debugged via Run-->Debug Configurations. But it asks me to click Debug. But my class does not have a main() method.
Say, I want to debug getValue() in Methods.java, now getValue() is invoked from a client (via tcp).
So, how do I attach the java process to eclipse remote debugger when that method is invoked? Am I missing out on something basic about remote debugging?
UPDATE: (I can see this in my debug view, that means, the remote app is connected and in the debug mode, now how do I put a breakpoint in the file where I want)
Add the line below:
-agentlib:jdwp=transport=dt_socket,address=1044,server=y,suspend=n
to run eclipse in debug mode
For eclipse, click on debug as icon > debug configurations > add a new remote java application > change the project to the project that you need and port to 1044 and click on apply and debug.
Put your breakpoint and access the remote application

Categories