How to fix NoClassDefFoundError on SpringApplication (Pivotal) - java

I've built a SpringBoot 2.1.5.RELEASE application using STS. Runs fine from STS. Dependencies downloaded into my .m2. Everything looks OK so far.
This application is packaged as a jar. I added main class using pom property. Manifest looks OK.
Now, I push this to Pivotal. It picks up java_buildpack_offline and appears to be installing but dies with
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication.
I'm new to cloud, so I'm hoping I'm missing a step somewhere. It just doesn't feel right to package a war with dependencies in the /lib folder. What would be the next step in sorting this out? Is there a dependency I need to include that specifically handles SpringBoot on cloud?

It seems that your jar file is not executable. For fixing it try to add the spring-boot-maven-plugin plugin, I hope it will help:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
...
</plugins>
</build>

Related

Run mvn install command skipping selected jar

What I need to do is to build a jar without one huuuge dependency, which is a fellow below
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-conversion</artifactId>
<version>21.1</version>
</dependency>
The system scope is one of solutions, but not in this case. None of my teammates would be happy to download a jar dependency manually.
Building a project including mentioned dependency creates a jar of 515 MBs or 251 MBs without it (system scope).
Thanks tgdavies for a hint with plugin. The thing that helped me was adding excludeGroupIds like below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>SECRET</mainClass>
<excludeGroupIds>com.groupdocs</excludeGroupIds>
</configuration>
</plugin>

NoModuleFileException: File does not exist for module having uri

I am deploying a J2ee project on websphere and I have set up artifacts,ear etc. with intelliJ.
It is a multi module maven project and was working fine till I have accidentally modified some set up in intelliJ.
What can be the reason? What intelliJ setting can influence this?I have tried to investigate pom but they looks fine and I haven not modified them before the issue.
The error is:
A file does not exist for module element having uri: namefile.war
If your war has snapshot change your ear plugin to skip versioning in the file name like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>6</version>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>

Diagnose NoClassDefFoundError during Spring Boot when class is available to ClassLoader

I have a Java/Maven project (POM-based) which builds and launches fine when using java -jar on the uber JAR produced by my Maven build on the command line, using the spring-boot-maven-plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.3.RELEASE</version>
<configuration>
<mainClass>com.company.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
The JAR is created (~100MB), and launches as expected.
However, I'm unable to launch this same application in Eclipse using the right-click -> Run As -> Java Application configuration on the main class I've defined in my POM. It's a Maven project, and M2E is up-to-date/refreshed, etc.
The error is:
java.lang.NoClassDefFoundError: Could not initialize class org.slf4j.LoggerFactory
So clearly some dependency issues with the logging frameworks. However: My first head-scratcher was, why does this work in Maven using the CLI, and fail in Eclipse using M2E?
So I went and looked at the classpaths, and they seem identical. (Looking at the Maven Dependencies list in Eclipse, and the BOOT-INF directory contained in my uber JAR.) The interesting bits are:
slf4j-api 1.7.25
log4j-over-slf4j 1.7.25
logback-core 1.2.3
logback-classic 1.2.3
commons-logging 1.1.3
So, I debugged. I placed a breakpoint on NoClassDefFoundError, and captured this. Note that the debugger is paused on the thrown exception, and the watch expression in the upper-right is getClass().getClassLoader().classes, which is a Vector.
How is it possible that we're throwing on LoggerFactory, even though this very class is present in the current ClassLoader? Where should I look next?
Edit: Since it's causing some confusion, the class in which Eclipse has caught this error (Category.java) is not one of my classes. It's inside a dependency (see Eclipse titlebar) and as a result cannot be modified.

maven adds version number to war - won't deploy

I'm using maven to build a war file for JBOSS AS 7. After a maven deploy, there is 'test.war' in the local repository, and a 'test-2.war' in the remote repository. This is all as expected (2 is the version in the POM).
If I manually deploy the 'test.war', everything works fine. If I deploy 'test-2.war' the deployment fails. If I rename 'test-2.war' to be 'test.war', the deployment works but trying to access it in a browser fails with error:
type Status report
message /test/Test
description The requested resource (/test/Test) is not available.
Since both war files are the result of the same maven build and deploy, why doesn't renaming the -2 version work the same as the first?
Is there a way I can deploy the -2 version without renaming, or what can I do to force the build so that I can rename the -2 version and have it deploy?
I know I can use maven's jboss deploy, but that's not an option in my case. I need the war file from the remote repository for manual deployments.
EDIT: The basic question here is why can't I rename the file {artifactId}-{version}.war to just {artifactId}.war and have it deploy in JBoss AS 7 properly?
You can rename the war like this:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warName>bird.war</warName>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
OR
<build>
<finalName>bird.war</finalName>
. . .
</build>
Take a look here

how to run a web service maven project on jetty 8 from eclipse?

I have a REST web service which I created previously and deployed in Tomcat7. I wanted to deploy it on Jetty, as advised in a previous question, I made a Maven project and copied my files there and configured the dependencies and I can run Maven install from eclipse successfully.
This is my build part in POM.xml:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<dependentWarExcludes></dependentWarExcludes>
<webappDirectory>
WebContent
</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
I followed instructions here to use maven jetty plug-in (I am not sure if this is required). The question here is how can I deploy my maven project in jetty from eclipse so that i can go to http:localhost:8080/myproject for example and see my project working?
EDIT:
The way I used to run the service on Tomcat was by right click on the project and click on Run As -> Run on server (which is configured in eclipse servers)
I am using eclipse Indigo, Maven 3 and jetty 8. Also I used jersey for the web service.
Here, you are mixing two different things:
Run your Web application using a Eclipse server plugin as Tomcat plugin for Eclipse.
Run your Web application using a Maven plugin as Jetty Maven plugin. There are also Maven plugins for Tomcat.
Having said that, take a look to this answer where it is described how to configure Eclipse to run Maven plugins (it could change depending on Eclipse version but idea would be similar)
Edited:
If you just want to run jetty from Maven, just use the following command line:
mvn jetty:run
But, in any case, I recommend that you indicate the Maven jetty plugin version in the pom file (Maven will warn you if you don't).
Edited 2
First, update your jetty maven plugin version:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
</plugin>
Second. You are working with two plugins, one for building the war file (maven-war-plugin) and another one for running your application on jetty (jetty-maven-plugin). Take in mind that jetty thinks your project has a standard maven project structure, it means, it will look for your web app content in /src/main/webapp but it looks like is not here. In your war plugin configuration, you specify that your web content is in WebContent, so tell jetty plugin that directory is there, as well as you are telling it to war plugin:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.0.M2</version>
<configuration>
<webAppSourceDirectory>/WebContent</webAppSourceDirectory>
<webXml>/over/here/web.xml</webXml>
<jettyEnvXml>/src/over/here/jetty-env.xml</jettyEnvXml>
<classesDirectory>/somewhere/else</classesDirectory>
<configuration>
</plugin>
See documentation. Of course, it is better to work with a standard maven project structure so you do not need to tell jetty where things are.

Categories