Spring Boot Thin Jar, How To? - spring

I want to use thin jar created by Spring Boot Maven Plugin (jarname.jar.original). I got all dependencies in lib directory. Tried to run. But it is giving following exception related to Banner. I tried to switch it off using spring.main.banner_mode=off. Why it is so obscure information about Spring boot thin jar ? I did not find any useful by googling.
java -cp 'target/thin-jar-0.1.0.jar:target/lib/*' com.example.cloudpayables.api.Application
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
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:497)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.showBanner(Z)Lorg/springframework/boot/builder/SpringApplicationBuilder;

I would recommend looking at the maven-dependency-plugin to make sure you are capturing all the required dependencies for your project. What I am guessing is missing is some transitive dependency.
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html
Josh Long will be very sad that the banner isn't showing and is causing the problem in your situation. :)

Related

ClassNotFound exception when I run my packaged jar, it works when launching it using Idea

The strange thing is that I don't use the missing class DispatchApplication and because I have no error when launching it using idea, so i do not know how to debug it.
I tried to clean idea cache, clean local maven repository, restart my PC
but my colleague can run with a jar, and each of them don't know why this happen and how solve this
D:\projectFolder\midel-data\data-integration\data-integration-service\target>java -jar data-integration-service-1.0.jar
Exception in thread "main" java.lang.ClassNotFoundException: com.lty.dispatch.DispatchApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
This looks to be an issue with dependencies.
You might want to check your IDE settings if you have explicitly enabled any additional jars in the class path.
Also, check out your pom.xml/.gradle file for any difference in dependency versions.
If this class is part of some custom jar, make sure you include it while packaging your jar.

Issues with spring cloud cli [NoSuchMethodError: org.springframework.cloud.launcher.cli.LauncherCommand]

I have spring boot of version
Spring CLI v2.1.0.RELEASE
And installed spring cloud of version
spring install org.springframework.cloud:spring-cloud-cli:2.0.0.RELEASE
It got installed properly, but not able to do any cloud cli commands, I'm running in to below exception
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoSuchMethodError: org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler.option(Ljava/util/Collection;Ljava/lang/String;)Ljoptsimple/OptionSpecBuilder;
at org.springframework.cloud.launcher.cli.LauncherCommand$LauncherOptionHandler.options(LauncherCommand.java:89)
at org.springframework.boot.cli.command.options.OptionHandler.getParser(OptionHandler.java:68)
at org.springframework.boot.cli.command.options.OptionHandler.getHelp(OptionHandler.java:99)
at org.springframework.boot.cli.command.OptionParsingCommand.getHelp(OptionParsingCommand.java:44)
at org.springframework.boot.cli.command.core.HelpCommand.run(HelpCommand.java:105)
at org.springframework.boot.cli.command.CommandRunner.run(CommandRunner.java:219)
at org.springframework.boot.cli.command.CommandRunner.runAndHandleErrors(CommandRunner.java:171)
at org.springframework.boot.cli.SpringCli.main(SpringCli.java:63)
... 8 more
Can any one help me to find out right/working version to be used.
I encountered the same issue. After 2 days investigation, I found it is a version issue. Please use spring-boot-cli-1.5.13.BUILD-20180509.054058-23-bin, the issue will be solved.
Issue resolved by using proper versions
Spring CLI v2.0.0.RELEASE
And Spring Cloud CLI v2.0.0.RELEASE

How to resolve conflict in maven dependencies apache: commons-fileupload 1.3.2 and commons-io 2.5

I have developed an app using jhipster generator. I have only slightly changed the pom.xml file. I needed the commons file-upload to be able to receive multipart requests. I am not sure but i believe that was the only change i have made.
I have only noticed the maven build problems when started trying to build the production image.
My IntelliJ uses bundled maven 2 and it works fine there, but when I switch back to maven 3 bundled or installed in my operating system (windows 7 x64) I receive this error.
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:50)
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/exception/ExceptionHandler
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at org.codehaus.plexus.classworlds.launcher.Launcher.getEnhancedMainMethod(Launcher.java:172)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:268)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.exception.ExceptionHandler
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 17 more
I believe one of the reasons my be conflict in my dependencies.
Here is snapshot of intelij analysis of my pom.xml.
[edit 1]
I have gave up trying to resolve this error. So what i tried to do now is to generate a new project with jhipster and copy all custom elements that was created by me into it.
And here i stumbled on a problem, which is i cant really do that, uperantly i have upgraded the jhipster-generator package incorrectly somewhere in the past.
So now on freshly generated projects i receive the same error + in my webapp bunch of files has an error like "ng-jhipster has no exported class AlertService" or the same but instead of AlertService its EventManager or some other class but it`s always the same package. Yes tried upgrading it.
I have found similar classes with Jhi prefixes on them in #ngx-jhipster package so it seams to me as as generator uses classes for one version of jhipster and package.json, pom.xml for another.
I tried upgrading the jhipster-generator, yarn and yo, removing the jhipster-generator dependency altogether and adding them back again, and generating projects again. Nothing worked =(

Exception: Multiple service implementations found for interface DeployableContainer when running Arquillian tests

I'm trying to follow the example project "Feedback" from Continuous Enterprise Development in Java, ch. 3 with a bit of modification.
I am using IntelliJ Idea and its JBoss-Forge plugin which shouldn't differ from using the console like in the book.
So far I've created a new project with the following characteristics:
Java 1.8
JEE 7
Wildfly 10.1.0.Final
JUnit 4.12
Arquillian 1.1.13.0
Hibernate
Maven profile: arquillian-wildfly-remote
I've followed every step from the tutorial, all using the IntelliJ plugin:
set ACCEPT_DEFAULTS true
created the project
set up persistence with Hibernate
set up validation with Hibernate validator
created entity FeedbackEntry
scaffolded the UI
forge install-plugin arquillian
set up Arquillian with Wildfly remote container
created an Arquillian
built and deploy the app
All of them ended successfully, I can open the UI and store some values in the DB. The problem comes when trying to run the test: I create an Wildfly Remote Arquillian container:
After clicking OK this is the stacktrace I get:
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:166)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:103)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:114)
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:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:162)
... 8 more
Caused by: org.jboss.arquillian.container.impl.ContainerCreationException: Could not create Container arquillian-wildfly-remote
at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:85)
at org.jboss.arquillian.container.impl.client.container.ContainerRegistryCreator.createRegistry(ContainerRegistryCreator.java:78)
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.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.ManagerImpl.bindAndFire(ManagerImpl.java:263)
at org.jboss.arquillian.core.impl.InstanceImpl.set(InstanceImpl.java:74)
at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:73)
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.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.ManagerImpl.start(ManagerImpl.java:288)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:63)
... 13 more
Caused by: java.lang.IllegalStateException: Multiple service implementations found for interface org.jboss.arquillian.container.spi.client.container.DeployableContainer. org.jboss.as.arquillian.container.remote.RemoteDeployableContainer, org.arquillian.container.chameleon.ChameleonContainer
at org.jboss.arquillian.core.impl.loadable.ServiceRegistryLoader.onlyOne(ServiceRegistryLoader.java:74)
at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:76)
... 37 more
Test ignored.
Test ignored.
Process finished with exit code 255
I've searched in many places and I only have found this. However I don't think I have more than 1 container, only Wildfly, so I'm completely clueless about this.
Pom and other key files here: https://gist.github.com/josemigallas/a139fc601b022356391fad5b2ec588b0
Why is this failing and how can I solve/workaround this issue?
From my experience, it might be an issue with Arquillian Plugin or IDEA Maven support having troubles with activating the profile. Please make sure that arquillian-wildfly-remote is in fact enabled by default (if it's ticked then untick and tick it again :)). Also run the test using regular JUnit runner, not the Arquillian one.
I think this is a problem when using IntelliJ with Arquillian support. Can you try to run it from CLI?

Spring Boot 1.4 to 1.5, unable to deploy

I have a very large and working Spring Boot project that is running OK with Boot 1.4.2. When I try to upgrade to 1.5.3 it works from my IDE (Intellij Idea) but it does not work on deployment. It's a Maven project, so I use the "package" directive to generate a WAR file and I get the error bellow on deployment. From what I can see, it says something is missing on the WAR but I even inspected it and the files are there... Any ideas?
Caused by: java.io.FileNotFoundException: file:(...)/target/ultraip-intranet-2.0-RELEASE.war*/WEB-INF/classes/com/ultraip/intranet/entities (No such file or directory)
at java.util.zip.ZipFile.open(Native Method) ~[na:1.8.0_131]
at java.util.zip.ZipFile.<init>(ZipFile.java:219) ~[na:1.8.0_131]
at java.util.zip.ZipFile.<init>(ZipFile.java:149) ~[na:1.8.0_131]
at java.util.jar.JarFile.<init>(JarFile.java:166) ~[na:1.8.0_131]
at java.util.jar.JarFile.<init>(JarFile.java:103) ~[na:1.8.0_131]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.doFindPathMatchingJarResources(PathMatchingResourcePatternResolver.java:593) ~[spring-core-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:475) ~[spring-core-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:279) ~[spring-core-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
at org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.buildDefaultPersistenceUnitInfo(DefaultPersistenceUnitManager.java:525) ~[spring-orm-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
... 105 common frames omitted
Screenshot of the generated WAR file
http://imgur.com/a/5aORQ
A change was made in Tomcat such that it now uses a * as the separator in war:file: URLs. This broke Spring Framework's resource resolution where the * was incorrectly interpreted as a wildcard.
The problem should have been been fixed in Spring Framework 4.3.8 which is used in Spring Boot 1.5.3 but it appears that you have found a case that wasn't considered. Can you please open a Spring Boot issue with a small sample that reproduces the problem?
You don't see the problem when you package your application as a jar file as that stops Tomcat from producing war:file: URLs for resources.

Resources