Wednesday, October 11, 2017

Show MBeans tab in Java VisualVM

To show the "MBeans" tab in Java VisualVM, check your Java version first as follows:

$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
$

Click as follows: Tools -> Plugins -> Settings

Use the following URL for "1.8.0_101": https://visualvm.github.io/pluginscenters.html

In the "Available Plugins" tab, install the "VisualVM-MBeans" plugin.

Now you can see the "MBeans" tab after reconnecting.

If you double-click a numeric read-only value, you can see a chart having 5 seconds resolution.

References:
https://stackoverflow.com/questions/38905119/java-visualvm-mbeans-plugin
https://visualvm.github.io/archive/uc/8u40/updates.xml.gz

Monday, September 11, 2017

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests$Foo]

When you build Spring Boot, you might encounter the following error:

java.lang.IllegalStateException: Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[startupFailure=org.springframework.beans.factory.BeanCreationException] failed to start

at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.getStartedApplicationContext(AssertProviderApplicationContextInvocationHandler.java:164)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.invokeApplicationContextMethod(AssertProviderApplicationContextInvocationHandler.java:155)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.invoke(AssertProviderApplicationContextInvocationHandler.java:87)
at com.sun.proxy.$Proxy41.getBean(Unknown Source)
at org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests.lambda$testNaming$0(ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java:47)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.accept(AbstractApplicationContextRunner.java:292)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$run$0(AbstractApplicationContextRunner.java:245)
at org.springframework.boot.test.util.TestPropertyValues.applyToSystemProperties(TestPropertyValues.java:129)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.run(AbstractApplicationContextRunner.java:243)
at org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests.testNaming(ConfigurationPropertiesReportEndpointMethodAnnotationsTests.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'foo': Could not bind properties to 'ConfigurationPropertiesReportEndpointMethodAnnotationsTests.Foo': prefix=first, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'first' to org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests$Foo
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:212)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.configureContext(AbstractApplicationContextRunner.java:287)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.createAndLoadContext(AbstractApplicationContextRunner.java:265)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.getContextOrStartupFailure(AssertProviderApplicationContextInvocationHandler.java:63)
at org.springframework.boot.test.context.assertj.AssertProviderApplicationContextInvocationHandler.<init>(AssertProviderApplicationContextInvocationHandler.java:50)
at org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider.get(ApplicationContextAssertProvider.java:111)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.createAssertableContext(AbstractApplicationContextRunner.java:258)
at org.springframework.boot.test.context.runner.AbstractApplicationContextRunner.lambda$run$0(AbstractApplicationContextRunner.java:244)
... 25 more
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'first' to org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests$Foo
at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:226)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:201)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:186)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:168)
at org.springframework.boot.context.properties.ConfigurationPropertiesBinder.bind(ConfigurationPropertiesBinder.java:101)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:209)
... 43 more
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.boot.actuate.endpoint.ConfigurationPropertiesReportEndpointMethodAnnotationsTests$Foo]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)
at org.springframework.boot.context.properties.bind.convert.BinderConversionService.lambda$convert$1(BinderConversionService.java:106)
at org.springframework.boot.context.properties.bind.convert.BinderConversionService.callConversionService(BinderConversionService.java:114)
at org.springframework.boot.context.properties.bind.convert.BinderConversionService.convert(BinderConversionService.java:106)
at org.springframework.boot.context.properties.bind.convert.BinderConversionService.convert(BinderConversionService.java:95)
at org.springframework.boot.context.properties.bind.Binder.bindProperty(Binder.java:289)
at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:248)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:197)
... 47 more

This was due to the environment variable as follows:

Johnnyui-MacBook-Pro:~ izeye$ env | grep "first"
_first=0
Johnnyui-MacBook-Pro:~ izeye$

But who set this? RVM 1.17.7 did!

Upgrading to RVM 1.29.3 with "rvm get stable" solves the problem as follows:

Johnnyui-MacBook-Pro:~ izeye$ env | grep "first"
Johnnyui-MacBook-Pro:~ izeye$

Reference:
https://github.com/rvm/rvm/issues/1851

Wednesday, August 23, 2017

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.BUILD-SNAPSHOT:start (pre-integration-test) on project start-stop-automatic-fork: Could not figure out if the application has started: Failed to connect to MBean server at port 50975: Spring application did not start before the configured timeout (30000ms -> [Help 1]

When building Spring Boot with "./mvnw clean install", you might encounter the following error:

[INFO] Exception in thread "main" java.lang.IllegalStateException: Shutdown should have been invoked by now
[INFO] at org.test.SampleApplication.main(SampleApplication.java:44)
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 34.455 s
[INFO] [INFO] Finished at: 2017-08-22T23:54:31+09:00
[INFO] [INFO] Final Memory: 23M/193M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.BUILD-SNAPSHOT:start (pre-integration-test) on project start-stop-automatic-fork: Could not figure out if the application has started: Failed to connect to MBean server at port 50975: Spring application did not start before the configured timeout (30000ms -> [Help 1]
[INFO] [ERROR]
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR]
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO]           start-stop-automatic-fork/pom.xml ................ FAILED (35.9 s)
[INFO]   The build exited with code 1. See /Users/izeye/IdeaProjects/spring-boot/spring-boot-tools/spring-boot-maven-plugin/target/it/start-stop-automatic-fork/build.log for details.

If you're using macOS Sierra (10.12.6), then try to modify "/etc/hosts" from:

127.0.0.1       localhost
::1             localhost

to:

127.0.0.1       localhost Johnnyui-MacBook-Pro.local
::1             localhost Johnnyui-MacBook-Pro.local

Reference:
https://thoeni.io/post/macos-sierra-java/

Wednesday, June 14, 2017

Increase max heap size for Gradle test

To increase max heap size for Gradle test, add the following to your "build.gradle":

test {
    maxHeapSize = "4g"
}

Reference:
https://docs.gradle.org/3.4/dsl/org.gradle.api.tasks.testing.Test.html

Monday, June 12, 2017

How to change "launchctl limit maxfiles"

You can change it as follows:

$ launchctl limit maxfiles
maxfiles    256            unlimited    
$ sysctl kern.maxfiles
kern.maxfiles: 12288
$ sudo vi /Library/LaunchDaemons/limit.maxfiles.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>65535</string>
      <string>65535</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

$ launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
$ launchctl limit maxfiles
maxfiles    256            unlimited    
$ sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
$ launchctl limit maxfiles
maxfiles    65535          65535    
$ sysctl kern.maxfiles
kern.maxfiles: 65535
$

Note loading the configuration without "sudo" didn't work.

Reference:
https://blog.dekstroza.io/ulimit-shenanigans-on-osx-el-capitan/

Sunday, May 21, 2017

Using MySQL in R

You can use MySQL in R as follows:

> install.packages("RMySQL")
...
> library(RMySQL)
Loading required package: DBI
> connection = dbConnect(MySQL(), dbname='test')
> dbListTables(connection)
[1] "animal" "person"
>

Reference:
https://www.r-bloggers.com/accessing-mysql-through-r/

Library not loaded: /opt/X11/lib/libSM.6.dylib

When you install RMySQL, you might encounter the following error:

> install.packages("RMySQL")
...
  unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so':
  dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib
  Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so
  Reason: image not found
>

Installing XQuartz solved the problem for me.

Reference:
http://stackoverflow.com/questions/26489928/cant-load-x11-in-r-after-os-x-yosemite-upgrade