Spring Boot 1.5.3 -- IllegalStateException - java

After deploying my project in IDE, all ok. But when I make 'package' at Maven, and tried to execute 'war' archive at the console, I get this exception:
Unable to open nested entry
'WEB-INF/lib/spring-aspects-4.3.8.RELEASE.jar'. It has been compressed
and nested jar files must be stored without compression. Please check
the mechanism used to create your executable jar file
At Spring Boot 1.5.2 was all good.

Looks like spring-aspects-4.3.8.RELEASE.jar that inside WEB-INF/lib/ is not extracted after compilation and your application can't extract classes from *.jar when you executing app.
Use maven dependencies instead direct *.jar files or specified plugin that will extract classes from *.jar's and add them to your app.
If you can't find public repository that provide required dependencies then use this instruction to add your external JAR files into your local maven repository. Then just add such dependency and build app again.

Related

Creating a jar from maven project Intellij

I created a new maven project in IntelliJ and set packaging to jar and when I build it, there is a jar file target folder. But when I run the file I get the error as
no main manifest attribute, in QeToolHelper-0.1-SNAPSHOT.jar
I have created jar file using maven-assembly-plugin. I have added these lines in pom.xml for that.
Tried few methods described in other similar questions but to no avail.
Have you looked at SpringBoot and associated plugins. It can be used to build a standalone java applications.
With regards to your specific issue, that error is symtomatic of a failure to declare main class in your manifest. The main-class attribute in the manifest tells the jvm what class to load from the built jar. Looks like the settings in your maven config are failing to generate the resources correctly.
I was able to solve this issue by creating jar package from maven.
Running the build package created the jar in target directory.

Building a fat JAR for Spring application without Maven or Gradle

I built a Spring application using Eclipse. Due to various reasons, I was not able to set the project up as a Maven or Gradle project, but rather with the external JAR files explicitly downloaded and added.
Currently I can run the application, Spring starts up normally and behaves fully as expected. The problem occurs however as soon as I want to package the project.
As there is no other option, I have to use Eclipse's packaging tools. This is what I do:
Export -> Java -> Runnable JAR file
Then I check the option Extract required libraries into generated JAR.
When executed the resulting JAR file always throws this error:
ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories.
If you are using a custom packaging, make sure that file is correct.
This spring.factories file looks like this:
org.springframework.beans.BeanInfoFactory=org.springframework.beans.ExtendedBeanInfoFactory
I am aware of the solutions to this problem involving the use of Maven or Gradle. But these can not be applied here.
How could I get the fat JAR to run without Maven or Gradle?

how to run external jar library in eclipse

I have just installed eclipse IDE for java and i am unable to execute code from external libraries, i know that we can't execute library code from unnamed package into a named package file, So i've put them both in default package, now i am able to access file from my external JAR library but i'm not able to get through this error, stating cannot connect to VM and some other boot layer error and i have no idea how to get through this...
The error occurs because of me adding jar library files to MODULEPATH instead of CLASSPATH. You have to add jar files to your CLASSPATH. If you already add jar files to MODLEPATH you have to remove from there and add jar files to CLASSPATH
as on : Error occurred during initialization of boot layer

Configure maven to package fat jar without unpacking dependencies in a vertx project, like spring boot does

How can I tell maven to include dependency jar files while building a fat jar, rather than unpacking them to .class files?
I have a vertx 3.6.0 project producing a fat jar. I am using vertx-maven-plugin:1.0.13, and I run mvn clean package to build. In order to take advantage of Veracode SCM (static scanning), the dependencies inside my fat jar have to be intact, meaning the original dependency jar files have to be contained inside my fat jar. Maven is unpacking all dependencies though, so all I have are class files.
We have another spring boot project which works as expected. It seems the final spring boot repackage goal puts all the dependency jar files in the BOOT-INF dir inside the jar file.
Final 2 goals using vertx-maven-plugin:
maven-jar-plugin:2.4:jar
vertx-maven-plugin:1.0.13:package
Final 2 goals using spring-boot-maven-plugin:
maven-jar-plugin:2.4:jar
spring-boot-maven-plugin:2.1.2.RELEASE:repackage
I've searched the docs for vertx-maven-plugin and all over https://maven.apache.org and elsewhere without any luck so far.
Is there a way to get this same repackage behavior for a non spring boot app?
You can't do that with Vert.x because it doesn't do fancy classloading.
But since it's embeddable, you can create a SpringBoot app that just starts Vert.x. Then you'll get your dependency scanner working.
But I would first check with Veracode if it' can't inspect your POM or Gradle build file instead of scanning a JAR.
If your packaging requirement is for the veracode scan piece, you would probably try packaging your project artifacts into a tar, or zip using the maven-assembly plugin.
Veracode couldn't scan a dependency jar inside another jar for a non-spring boot project. So, you can try one of the following. i) tar packaging using maven-assembler plugin, or ii) convert it to spring-boot project if thats simpler and you could ,or iii) uber-jar creation using maven-shade plugin and need to make some configuration changes for not getting unpackaged to .class files. Still would suggest you can explore with the tar packaging option - (reference:) https://maven.apache.org/plugins/maven-assembly-plugin/

How to export external jars along with the project while creating jar of a project [duplicate]

How can I add an external library to a project in IntelliJ IDEA so that when I build an artifact it still has access to the classes in the library?
I have created a new Jar artifact from Project Structure, then added the external JAR to the Libraries, then checked it in the Modules List, and finally added it to the Output for the Artifact. None of these work. When I build and try running my application, it throws an error:
Exception in thread "main" java.lang.NoClassDefFoundError: <path of the class trying to use>
What am I missing, or am I doing this completely wrong?
You have 2 options here:
extract the dependency into the artifact jar so that the app is the single executable jar with all the dependencies
link the dependent jars via the Manifest.MF and copy them near the application main jar
I've prepared a sample project that demonstrates both approaches: HelloWithDependencies.zip.
The artifacts are produced into out\single and out\linked directories.
Relevant configurations:
If you are using maven to build your application then this is not the correct way to add external library. You should either
Do an install of your library like below mvn install:install-file -Dfile=myJar.jar -DgroupId=com.yourproject -DartifactId=yourproject -Dversion={version} -Dpackaging=jar.
Use system path like explained here.
Option 1 is prefered since you don't have to keep jar in your project.

Categories