In a spring boot project who use maven. A class is not found
A part of my pom
<groupId>com.acme.pay</groupId>
<artifactId>ms.billing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ms.billing</name>
<packaging>jar</packaging>
<properties>
<default.package>com.acme.pay.ms.billing</default.package>
</properties>
Structure of the project
com
acme
pay
ms
billing
domain
v2
BillingServiceApplication.java
When I start application, I get this error
Error: Could not find or load main class com.acme.pay.ms.BillingServiceApplication
Caused by: java.lang.ClassNotFoundException: com.acme.pay.ms.BillingServiceApplication
Command execution failed.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project ms.billing: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
It seem it don't seem in the correct path.
Your problem might be related to your artifactId having a . character in it. I've never seen an artifactId formatted like that and I think it might be messing up the path resolution. Usually people use - as a separator when they want to make an artifactId more readable (as per commons-math in the maven guide linked below).
http://maven.apache.org/guides/mini/guide-naming-conventions.html
choose whatever name you want with lowercase letters and no strange symbols
Can you please confirm if your application is 'Spring Boot' application?
If yes, then while running your application as 'Java application', just choose the main file as 'BillingServiceApplication'. There is no problem with your pom file.
If no, then could you please share your pom file with all dependencies?
I think that you need to change the version of the following dependency
'org.codehaus.mojo:exec-maven-plugin'.
Just check the link for similar question on stackoverflow:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli)
I hope this helps!
did you annotate your class with #Component, #Services etc
OR
if your class out of the scan scoop you could included it via
#ComponentScan(basePackages = "com.acme.pay.ms.billing")
#Configuration
public class SpringComponentScanApp {
Or you could use xml as in your case via
<context:component-scan base-package="com.acme.pay.ms.billing" />
Package of BillingServiceApplication should be com.acme.pay.ms.billing.BillingServiceApplication
Related
I have created a Spring Boot application, I have build the project and selected the main class and I have also added properties in my pom.xml:
<properties>
<java.version>1.8</java.version>
<start-class>com.mua.scraper.ScraperApplication</start-class>
</properties>
Now the problem is when I try to run the .jar file, it tell me that MainClassNotFound. Here is a snap:
Later project will be opend here
After changing the command, here is my output:
Error:
No main artifact
You are missing -jar to properly run the jar file. It should be:
java -jar scrapper.jar
Actually the problem was in my artifact, so here is what I have done:
Opened Project Structure(CTRL+ALT+SHIFT+S)
Navigate to Artifacts -> JAR -> From module with dependencies
Then Selected Main class, or the entry class
Copy the output directory and link via manifest(I made the mistake here)
Don't forget to select that directory as in the picture
I follow along with the tutorial Hello Spring Security with Boot to learn Spring Security.
After importing it into STS,I got build errors:
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-thymeleaf:jar is missing.
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing.
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing.
I thought the sample comes from official GitHub repository, so it should work well. Unfortunately, I encounter build errors.
Then I tried to fix the build errors. I appended <version>1.5.3.release</version> tags in POM file and the errors from POM file disappeared.
But I still encountered an error from main class:
The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
I have used all spring samples from official site and it works.
my sample pom file is as below,
https://github.com/Roshanmutha/rcmutha-springrest/blob/master/pom.xml
Only will have addition and removal as per the sample you are trying.
Click the below link to see all sample which i have tried from spring repo :
https://github.com/Roshanmutha?utf8=%E2%9C%93&tab=repositories&q=rcmutha&type=&language=
I have update my project to use Spring BOOT 1.4.3. The code compiles and runs without issues from Eclipse Neon 1.
But when I run from command line
mvn clean install -DskipTests
java -jar myweb\target\my-web-1.0-SNAPSHOT.jar
I get runtime error and tomcat is not starting
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:43) ~[tomcat-embed-core-8.5.6.jar!/:8.5.6]
Please can you tell why? How to find which tomcat is used at runtime, as my understand is that 8.5.6 is having compile scope(?)
Please help. If the suggestion is to use tomcat.version in properties of POM file or add tomcat-juli dependency, then please help me understand why it is required?
Impatient stackoverflow'ers dont just flog new comers only because you can do. You can easily ask if you want my POM, but I used just spring-boot-starter-web thats it.
For this kind of problem, it's often due to multiple jar having the same class inside your classpath, so :
Find where this class / method could come from, by opening the type popup (CTRL + SHIFT + T in Eclipse). It will display you every jar in your classpath that contains the class.
Open the class in each jar to see which one contains your method and which one don't.
Display the dependency hierarchy of your project with mvn dependency:tree
If the 2 jars are in your classpath, you might exclude the one that don't contain the method.
I'm trying to run 'mvn clean install' in a sub-module of a multi-module project. The project is Jacoco but I assume it's more an issue of me not understanding how Maven is being used here than an issue with Jacoco itself.
https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-site/pom.xml
I get the following error:
[ERROR] Plugin #project.groupId#:jacoco-maven-plugin:#project.version#
or one of its dependencies could not be resolved: Failed to read
artifact descriptor for
#project.groupId#:jacoco-maven-plugin:jar:#project.version#
I see the following in the pom:
<groupId>#project.groupId#</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
I'm not familiar with using the # symbol in #project.groupId# although i assume it is somehow supposed to get substituted at runtime.
I can run Maven from the top level pom and I even see [INFO] Building: it-site/pom.xml in the log but a target directory is not created there.
A nudge in the right direction would be appreciated.
This probably has something to do with the pom file here: https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/pom.xml
It is using a plugin called the maven invoker.
The Invoker Plugin is used to run a set of Maven projects. The plugin can determine whether each project execution is successful, and optionally can verify the output generated from a given project execution.
And if you read about filtering files with this plugin, it mentions:
POM files selected by the include/exclude patterns. The tokens to be filtered must be enclosed in #...# to avoid interferences with Maven's normal POM interpolation, i.e. use #project.version# instead of ${project.version}.
Regarding why the Invoker Plugin and filtering is being used here...
The Spring Boot documentation provides some relevant background on why that is. Although the docs are for Spring Boot, i think it applies to testing all plugins (which Jacoco is).
Multi-module Maven builds cannot directly include maven plugins that
are part of the reactor unless they have previously been built. ...
The standard build works around this restriction by launching the
samples via the maven-invoker-plugin so that they are not part of the
reactor.
The sample application are used as integration tests during the build
(when you mvn install). Due to the fact that they make use of the
spring-boot-maven-plugin they cannot be called directly, and so
instead are launched via the maven-invoker-plugin.
Background:
I am developing Maven multi module project.
One of the module is common module needed by other all modules.
This module contain CommonClassA.java.
common module is properly compiled.
It is installed into maven local repository properly.
One of the class(Billtype.java) in other module (EmployeeBilling) refers this class(CommonClassA.java).
Maven Dependency for common module is properly specified in pom.xml of EmployeeBilling module.
Problem:
While compiling EmployeeBilling module it throws
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project EmployeeBilling: Compilation failure
[ERROR] \MyWorkspace\Biz\EmployeeBilling\src\main\java\com\employee\Billtype.java:[79,19] error: cannot access CommonClassA
[ERROR] -> [Help 1]**
Supporting details:
dependency defined in EmployeeBilling> pom.xml:
Other classes from common module seems accessible as no error observed
There are no other errors like Class not found/file not found.
The class CommonCLassA implements Serializable
Same error occurs from Eclipse as well as commond line
I am using M2E plugin
Tools:
jdk1.7.0_02
OS: Windows 7
Eclipse JUNO and apache-maven-3.1.0
Thanks in advance!
If project builds properly using eclipse compiler then it should work with Maven.
Few things to check if its not working with maven:
Manually check in repository that jar is installed properly and it contains your class file.
Try to build project using locally installed Maven instead of maven in eclipse.
Set -DskipTest=true while installing your jar, as it can cause issues at times.
If these steps don't work then show us your pom.
With no more information it's hard to find the cause. But I also had this problems now and then, and there are some things which could go wrong:
Are you using the right JAVA version (everywhere) ?
... and the right java PROVIDER? (Oracle, IBM, OpenJDK) In my case it's often this issue, I'm sometimes bound to IBM JDK, although I try to use Oracle where I can and this sometimes breaks my build.
Is the right maven dependency VERSION used? If you depend on it multiple times, and all in the same (lower than root) dept of dependencies, Maven will just "choose" a version. It could be that thát version is incompatible with your code of thát particular dependency
Skipping tests sometimes WORKS! It has something to do with maven phases and getting stuff ready for using it elsewhere.
Good luck :)
I had the same problem. Even the jar dependency has the required class files. Finally I deleted the local maven repo and restarted the build. Now it worked without any issue.
It looks like you are using an old version of maven-compiler-plugin (v2.3.2).
I suggest you upgrade it to 3.x. it won't magically fix your issue but it will definitely give you better / more detailed error message.