NPE on startup of java -jar hawtio-app-1.2-M26.jar #718

Closed
fancellu opened this Issue Nov 3, 2013 · 17 comments

Projects

None yet

2 participants

@fancellu
fancellu commented Nov 3, 2013

JDK 1.7 u40.

Following getting started instructions:

Failed running hawtio: null
java.lang.NullPointerException
at java.io.File.(File.java:277)
at io.hawt.embedded.Main.findWar(Main.java:128)
at io.hawt.embedded.Main.run(Main.java:81)
at io.hawt.embedded.Main.run(Main.java:70)
at io.hawt.app.App.main(App.java:82)

Any idea?

@jstrachan
Member

This sounds like this issue: #579

I wonder if you could try out the latest snapshot from here:
https://oss.sonatype.org/content/repositories/snapshots/io/hawt/hawtio-app/1.2-SNAPSHOT/

as I think this fix might have fixed the NullPointerException at least
6912693

@fancellu
fancellu commented Nov 4, 2013

Runs up thanks, no NPE. But does throw errors on startup:

 Failed to load class com.sun.tools.attach.VirtualMachine and find tools.jar at C:\Program Files\Java\jre7\lib\tools.jar. java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine

Now, that is my JRE, so won't find tools.jar, that is in my JDK

My JAVA_HOME is pointing to my full JDK dir.

If I change dir to %JAVA_HOME%\bin and run java from there, its finds tools.jar just fine

So you might like to try looking in the %JAVA_HOME%\lib dir for tools.jar

@fancellu
fancellu commented Nov 4, 2013

By the way, connect/local tab is missing

stdout says:

25103 [main] WARN io.hawt.jvm.local.JVMList - Local JVM discovery disabled as th
is JVM cannot access com.sun.tools.attach.VirtualMachine due to: java.lang.NoCla
ssDefFoundError: com/sun/tools/attach/VirtualMachine

com.sun.tools.attach.VirtualMachine certainly does exist in tools.jar

I am running Windows 7, JDK 7 u40, 64bit

@jstrachan
Member

Yeah, the Connect/Local tab is hidden if we can't find the com.sun.tools.attach.VirtualMachine class (as it would fail if we tried to show it).

@fancellu great idea on the use of $JAVA_HOME ;)

I just updated the code to be a little more flexible; so we'll now try in both the java.home system property and $JAVA_HOME environment variable with and without the jre subdirectory added to try find tools.jar.

Fingers crossed this helps on windows!

I've kicked off a new snapshot build - any chance you could try it out if you get the chance please?
https://oss.sonatype.org/content/repositories/snapshots/io/hawt/hawtio-app/1.2-SNAPSHOT/

@fancellu
fancellu commented Nov 4, 2013

That new snapshot works fine thanks.

However don't understand why com.sun.tools.attach.VirtualMachine not being seen

It can find the tools.jar

extraClassPath=...pathtotools.jar

Interestingly, when I start up java verbose I can't see any other mentions of tools.jar

@jstrachan
Member

So does the Connect / Local tab appear for you now? I hope so! These changes should hopefully mean we find tools.jar.

For some reason we've had to hack it to find tools.jar as the class is often not visible via a Class.forName(...)

@fancellu
fancellu commented Nov 4, 2013

Nope. It says

24977 [main] WARN io.hawt.jvm.local.JVMList - Local JVM discovery disabled as this JVM cannot access com.sun.tools.attach.VirtualMachine due to: java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine

It does find tools.jar just fine though, sticks it on extraClassPath, but can see no classloading of tools.jar when starting in verbose mode

So I suspect its not getting on the real classpath.

@jstrachan
Member

damn! I wonder if using the file name, rather than a URL works better on windows? e.g. removing the "file://" prefix from this line of code?
https://github.com/hawtio/hawtio/blob/master/hawtio-app/src/main/java/io/hawt/app/App.java#L66

any chance you could try build the hawtio-app module locally and see if that helps? Its odd - as this finding of tools.jar works on OS X just fine. I guess tools.jar does include the "com.sun.tools.attach.VirtualMachine " class right?

@fancellu
fancellu commented Nov 4, 2013

Don't have time for that, however: progress.

java -jar hawtio-app-1.2-20131104.090952-57.jar -ecp "%JAVA_HOME%\lib\tools.jar"

The quotes are there as I have spaces in my JAVA_HOME path.

Now sees tools.jar, does not complain the same way, we now have a local tab, but it does not work.

Could not discover local JVM processes

Maybe because of this in the stdout:

java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated: java.lang.UnsatisfiedLinkError: no attach in java.library.path
@fancellu
fancellu commented Nov 4, 2013

Aha, a fix

It is looking for attach.dll, which only seems to be in JAVA_HOME\jre\bin not bin

http://stackoverflow.com/questions/14027164/fix-the-java-lang-unsatisfiedlinkerror-no-attach-in-java-library-path

So I:

set path=%path%;%JAVA_HOME%\jre\bin

Local connect no works lovely, ran up a new VM, refreshed, found it, connected etc.

@jstrachan
Member

YAY! :)

I've just tried another patch to wrap the discovered tools.jar in quotes if we find a space in the path; and to use the file name rather than a URL just in case that helps. There's a CI build running now - in about 20 mins or so there should be a newer snapshot available here:
https://oss.sonatype.org/content/repositories/snapshots/io/hawt/hawtio-app/1.2-SNAPSHOT/ - after the "hawtio-app-1.2-20131104.111102-58.jar" one - fingers crossed this one just works without having to mess around!

@fancellu
fancellu commented Nov 4, 2013
java -jar hawtio-app-1.2-20131104.113235-59.jar

Bang!

69 [main] INFO org.eclipse.jetty.server.Server - jetty-8.y.z-SNAPSHOT
99 [main] WARN org.eclipse.jetty.webapp.WebAppContext - Failed startup of contex
t o.e.j.w.WebAppContext{/hawtio,null},C:\Users\Dino\AppData\Local\Temp\hawtio-48
34898066425731884.war
java.net.MalformedURLException: no protocol: "E:\Program Files\Java\jdk1.7.0_40
lib\tools.jar"
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at java.net.URL.(Unknown Source)
at org.eclipse.jetty.util.resource.Resource.newResource(Resource.java:15
0)
at org.eclipse.jetty.util.resource.Resource.newResource(Resource.java:13
4)
at org.eclipse.jetty.server.handler.ContextHandler.newResource(ContextHa
ndler.java:1568)
at org.eclipse.jetty.webapp.WebAppClassLoader.addClassPath(WebAppClassLo
ader.java:220)
at org.eclipse.jetty.webapp.WebAppClassLoader.(WebAppClassLoader.j
ava:157)
at org.eclipse.jetty.webapp.WebAppClassLoader.(WebAppClassLoader.j
ava:126)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.jav
a:396)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:453
)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:59)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrappe
r.java:90)
at org.eclipse.jetty.server.Server.doStart(Server.java:262)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:59)
at io.hawt.embedded.Main.run(Main.java:102)
at io.hawt.embedded.Main.run(Main.java:70)
at io.hawt.app.App.main(App.java:103)
147 [main] INFO org.eclipse.jetty.server.AbstractConnector - Started SelectChann
elConnector@0.0.0.0:8080

@jstrachan
Member

thanks for the prompt feedback! :)

I wonder if this one works any better? tried avoiding using quotes and strings and instead just use the URL from the file object; which I'm hoping does the right thing on windows
https://oss.sonatype.org/content/repositories/snapshots/io/hawt/hawtio-app/1.2-SNAPSHOT/hawtio-app-1.2-20131104.115348-60.jar

@fancellu
fancellu commented Nov 4, 2013

Yes, works fine.

extraClassPath=file:/E:/Program%20Files/Java/jdk1.7.0_40/lib/tools.jar

Hurrah!

DIno.

On 4 November 2013 12:03, James Strachan notifications@github.com wrote:

thanks for the prompt feedback! :)

I wonder if this one works any better? tried avoiding using quotes and
strings and instead just use the URL from the file object; which I'm hoping
does the right thing on windows

https://oss.sonatype.org/content/repositories/snapshots/io/hawt/hawtio-app/1.2-SNAPSHOT/hawtio-app-1.2-20131104.115348-60.jar


Reply to this email directly or view it on GitHubhttps://github.com/hawtio/hawtio/issues/718#issuecomment-27680444
.

@jstrachan
Member

@fancellu huge thanks for your help and patience! I'll cut a new milestone now - many thanks!

@jstrachan
Member

fixed in 1.2-M27

@jstrachan jstrachan closed this Nov 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment