Configuring Jersey-Maven project in Eclipse - java

I am trying to write a sample REST web services demo using Jersey.
After creating a Maven project - this is the error I have
Description Resource Path Location Type Cannot read lifecycle mapping
metadata for artifact
org.apache.maven.plugins:maven-clean-plugin:maven-plugin:2.5:runtime
Cause: error in opening zip file pom.xml /MyRestDemo line 1 Maven
Project Build Lifecycle Mapping Problem
Screen shot
Per suggestions on previous stack overflow posts,
I have deleted the .m2 repository and updated the project - error persists.
I have deleted just maven - clean plugin still have the same error.
I have the same error with both Eclipse Neon and Luna and I am stuck at this point.
Thanks

Set of Actions that could be taken according to eclipse foundation: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
Modify you POM.xml with below plugin.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
The above should work fine, if still you are facing problem then Go to
.m2/repository , delete all files. come to eclipse and rebuild your project.
One more reason for the above error could be a bad download of artifact, please check the proxy details of your company or home in (~/.m2/settings.xml)

This is an extremely weird error message:
org.apache.maven.plugins:maven-clean-plugin:maven-plugin:2.5:runtime
Cause: error in opening zip file pom.xml
"ZIP file pom.xml"? Why would it think that? Maybe try to run Maven from the command line (or using Run -> "Maven ..." inside of Eclipse). That might give you a different / better error message.
If that doesn't help, some background: m2e (the Maven plugin for Eclipse) tries to figure out which Maven targets it should run as part of the build inside of Eclipse. mvn clean is one of them. To see what m2e thinks, select the project, right click, Properties, Maven, "Lifecycle Mapping".
The target clean:clean should be mapped to "ignore" since Eclipse already does that well.
Which makes me wonder why it wants to run in your case.
If the mapping is correct for you, then sometimes m2e get stuck in weird ways. Try to update the project (right click project, Maven, "Update Project..."). Make sure "Update project configuration from pom.xml" is enabled.
If that also doesn't work, then something broke your Eclipse installation. Try to install the latest version of Eclipse and try to open the project there.

Related

Why am I receiving this 404 Error in my Maven Dynamic Web Module?

I'm brand-new to Jersey/JAX-RS/RESTful Web Services/etc. and I'm having difficulty with a Jersey archetype called jersey-quickstart-webapp. I'm attempting to use it with Eclipse, Maven, and Tomcat v7 or v8 (I've tried both).
First I got a JSP error:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path.
I resolved that error with this SO question regarding the error. Apparently Maven wasn't treating my project as a Dynamic Web Application.
Then I got a warning about:
Build path specifies execution environment JavaSE-1.7. There are no JREs installed in the workspace that are strictly compatible with this environment. I resolved the second issue with another SO question on the matter. I was originally using JavaSE-1.8.
Finally, I had one last error:
Classpath entry org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result.Again, I checked SO on the matter and excluded the associated raw classpath entry from the set of potential publish/export dependencies.
However, I am still given a 404 on my project and I cannot figure out why. I'm using a pom.xml file for this project. The tutorial I'm following is telling me that the correct URL to be using here is http://localhost:8080/messenger/.
This is not an answer (will be deleted)
Edit: Turned into community wiki. It's not a solution.
Try and add this jetty plugin to the app. Inside the <build><plugins> in the pom.xml file
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.6.v20141205</version>
</plugin>
Then Right click on project, Maven -> Build; in the dialog on the goals type jetty:run and try to run the build. This should start an embedded jetty server. Once the console says "Jetty Server started", you should be able to access http://localhost:8080/webapi/myresource. Just want to see if it is a problem with the app.
Fast Temporary solution:
Change webapi to webresources in the url: http://localhost:8080/webapi/myresource
Permanent solution:
Change the file web.xml
<url-pattern>/webresources/*</url-pattern>
to
<url-pattern>/webapi/*</url-pattern>

Spring Boot Program cannot find main class

I have a program which runs as a Spring boot App in eclipse. The program was running fine. Then i did the following:
Right click on project -> Run As -> Maven Test .
This was accidental. When i then tried to run the program as a spring boot app again, it threw the following error below.
Error: Could not find or load main class com.bt.collab.alu.api.webapp.Application
How do i point the application back to my main class?
Thanks
I had the same problem. Try this :
Right Click the project -> Maven -> Update Project
Then Re-run the project. Hope it work for you too.
Main class is configurable in pom.xml
<properties>
<start-class>com.bt.collab.alu.api.webapp.Application</start-class>
</properties>
Have a look under "Run -> Run Configurations..." in Eclipse. You should delete the new one which you created by mistake, you should still have the existing one.
I suspect it has created a new run configuration for the "Run as Maven Test" and you are now always starting this one.
If you're using Spring Boot and the above suggestions don't work, you might want to look at the Eclipse Problems view (available at Window -> Show View -> Problems).
For example, you can get the same error (Error: Could not find or load main class groupId.Application) if one of your jar files is corrupted. Eclipse will complain that it can't find the Applications class, even though the bad jar is the root cause.
The Problems view, however, will identify the bad jar for you.
At any rate, I had to manually go to my local mvn repo (in .m2) and manually delete the corrupted jar, and update it (right click on the project in the Package Explorer), Maven --> Update Project... -> OK (assuming that the correct project is check-marked).
I tried all the above solution, but didn't worked for me.
Finally was able to resolve it with a simple fix.
on STS,
Run Configuration > open your Spring Boot App > Open your configuration,
Follow the steps,
In Spring boot Tab, check your Main class and profile.
Then go to classpath tab, In the bottom you will see two checkboxes,one is "Exclude Test Code"(Check this if you do not want to run test classes) and other, "Use Temporary Jar file to specify classpath" (this is necessary).
Save your configuration and run.
This happened to me after i updated the pom (Added some dependencies).
The following step helped me to avoid this error
right click on the project > maven > update project
Intellij
close Intellij
remove all files related to Intellij (.idea folder and *.iml files)
open the project in Intellij as if it was the first time (using open recent won't work, id needs to be done via file -> open)
Use spring-boot:run command to start spring boot application:
Precondition:
1. Add following property to pom.xml
<property>
<start-class>com.package.name.YourApplicationMainClass</start-class>
</property>
2. Build your project
Then configure maven command with spring-boot:run.
Navigation:
Right Click Project | Run As | Run Configuration... | Add new Maven Configuration with command spring-boot:run
In case if someone is using Gradle for the build then fix will be by adding the following lines in build.gradle file
apply plugin: 'application'
mainClassName = "com.example.demo.DemoApplication"
The solution for me was:
Boot Dashboard, right click on your Instance.
Open Config
Tab Spring Boot
Main Type, there was the path to the application file missing...
I know this is pretty late answer. But it might still help some new learners.
The Following example is only for springboot with NETBEANS.
I had to do the following steps:
Step 1. Follow #Mariuszs answer .
Step 2. Right click on project -> Properties -> RUN.
Make sure the Main Class field is has the correct starter class else Click browse and select from the available classes .
Step 3. Click OK-> OK. Thant is all. Thank you.
I have used spring 1.5.3.RELEASE version and given pom dependencies like
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
And my main class was
#SpringBootApplication
public class SpringAppStarter {
public static void main(String[] args) {
SpringApplication.run(SpringAppStarter.class, args);
}
}
But still while execution of main class I was getting:
Could not find or load main class ... with my class name.
I could see that class was available in the class path and I was using STS IDE.
I was not getting reason for the issue then I tried manual build through maven with
mvn clean install
Still problem was there then i realize that my project has two libraries
Reference Library
Maven Library
What I did:
I have created another mavenRepo folder and build it again and refresh my project. After that it worked and I saw that Maven Library was deleted from project class path.
Issues was while execution it was getting multiple version so it was not able to find proper class to execute my application.
Other Solution listed in this page also resolves the issue but if you are doing mistake in
Annotating class
pom entry
jar version etc.
Hope this may resolve problem if somebody get this issue
deleting old jars from .m2 and updating maven project should be primary step.
In most of the cases it resolves the issue.The reason for this issue is mostly corrupted old jars
Encountered the same issue and was able to fix it by the following the steps listed below:
File -> Invalidate Cache and Restart
File -> New -> Project from existing source
Select the pom.xml file just (not the whole project directory) to load the project. Project will be setup automatically.
Error:Could not load or find main class
Project:Spring Boot
Tool:STS
Resolve Steps:
Run the project
See in problems tab, it will show the corrupted error
Delete that particular jar(corrupted jar) in .m2 folder
Update project
Run successfully
I was having the same problem just delete .m2 folder folder from your local repositry
Hope it will work.
start-class doesn't work for me, I fixed it by adding build plugins to pom.xml, and executions is necessary.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
There are good answers here, but maybe this one will also help somebody.
For me it happened just after i deleted .idea (with IntelliJ), and reimported the project.
then this issue started, i tried to run mvn compile (just via IDE Maven toolbar), once i fixed few compilation errors, issue disappeared
If you came across the
error:could not find or load main class in maven project
do this it worked for me:
Reason for the error: The reason for this error is the jar file or dependency to run a maven project is not installed correctly.
Solution for the error: Go to the project folder (eg: D:\office\OIA-service-app)
in the address bar of computer type command cmd and press enter.
In the command prompt type command mvn clean install make sure you have the internet connection.
If your project packaging type war you could not start. I was using maven assembly plugin with this configuration;
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version><!--$NO-MVN-MAN-VER$ -->
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.ttech.VideoUploaderApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
and my packaging tpe was war i got cannot find main class exception bu i changed packaging to jar it worked;
<groupId>com.ttect</groupId>
<artifactId>VideoUploadListener</artifactId>
<version>1.0.0</version>
<packaging>**jar**</packaging>
In my case the following helped:
Added the following section in pom
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
Ran it using maven3 and it worked
I also got this error, was not having any clue. I could see the class and jars in Target folder. I later installed Maven 3.5, switched my local repo from C drive to other drive through conf/settings.xml of Maven. It worked perfectly fine after that. I think having local repo in C drive was main issue. Even though repo was having full access.
I was facing the same problem. I have deleted the target folder and run maven install, it worked.
I had similar kind of problem while I was adding spring security dependency to my project ,
then I deleted my target folder and used maven update again .
It's worked for me.
Even I faced the same issue, later I found that it happened because the maven build operation was not happening properly in my environment. Please check it in your case also.
I ran into same error, although i was using gradle build. Delegating IDE build/run actions to Gradle is solved my problem.
Intellij:
Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner
I got the same error in the "Spring Tool Suite" software.
In my case, I have Java 8 installed and I created a project of Java 11. And when I run the project I got the same error, like " can not find main class ".
Then I created a project in Java 8 and the problem resolved.
(Eclipse) Updating maven project was not working for me. What I had to do was to go in Run configurations, and in "Main" tab, in "Project" field, write the whole package name com.bla.blabla.MyMainClass (instead of just the Main class name).
The error happened because I have several projects with the same name, but in different packages.
if none of above solutions work, try to replace build tag with this inside pom file :
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins></pluginManagement>
</build>
I am new in spring boot and using STS with maven build. I did all the things mentioned above but won't work for me. I noticed two problems in problem window of STS. There was a missing jar file on the path (C:\Users\UserName.m2\repository\com\jayway\jsonpath\json-path\2.2.0). I did following, the way is not strongly suggested but worked for me.
1) I deleted .m2 folder from the path location
2) Restarted STS
3) Right Click on project folder -> maven -> update project -> checked "Force update of snapshots/releases" -> Click Ok.
Maven updated its dependencies and the problem is solved.

Failed to copy artifact or file with maven packaging a web application

I have a problem packaging a web application based on vaadin. I have two projects in my workspace called project A and project B. Project A is referencing B and the dependencies are resolven within the workspace and degub mode correctly, by adding the project to the classpath.
Now if I try to maven package, I always get the error
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project A: Failed to copy file for artifact [com.dscsag.dscxps:ProjectB:jar:0.0.1-SNAPSHOT:compile]: C:\some_path\target\classes (Access is denied) -> [Help 1]
What should I do?
I had the same error message before. In pom.xml I changed maven-war-plugin version from 2.3 to 2.6, then the project was built successfully.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
</plugin>
This has nothing to do with security: under Windows, this problem occurs when a process doesn't "close" correctly its usage of a folder.
We got the problem with apt-maven-plugin: in a complex multi-modules project, when a module using this plug-in, is then later referenced in an über jar building pom, then we got this error during the build of the über jar on the target/classes folder of the module using apt-maven-plugin.
When resuming the build (mvn params -rf :offending_module), the problem disappears because the Maven process launching the apt-maven-plugin is dead, thus the lock of the folder is released.
Very annoying to say the least.
It seems to relate with security because the log said "(Access is denied)". Maybe the output jar of project B exists and there are some processes still reading from it, so that you cannot overwrite the output file. Or maven doesn't have the appropriate privilege to write the output file to the class folder.
In my experience, in the Maven plugin doing the copying (artifact maven-resources-plugin for me), the outputDirectory element was the issue, because I just had a slash as the output directory. I think this was causing Maven to try to copy this to C:/, and I need admin access to place files in C:/. Changing the outputDirectory to ${basedir}/target/resources got rid of this error.

Intellij 13 Ultimate not able to find supported files

I'm using Intellij 13 Ultimate on Windows 7 enterprise. My maven pom includes the following:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration/>
</plugin>
</plugins>
</reporting>
I have settings.xml configured to access Nexus repositories within the firm for whom I am working.
Within intellij, the '2.9.1' displays in red and I see : Plugin "org.apache.maven.plugins:maven-javadoc-plugin:2.9.1" not found.
At the windows command line, though, I am able to download the artifact to the local repo using the same settings.xml file and the command:
C:\swdtools\apache-maven-3.1.1\bin>mvn org.apache.maven.plugins:maven-dependency
-plugin:2.1:get -DrepoUrl=https://dsnexus.uk.<HIDDEN>.<HIDDEN>:8081/nexus -Dartifact=org
.apache.maven.plugins:maven-javadoc-plugin:2.9.1
Intellij doesn't pick it up if I do 'reimport all maven projects'.How to fix or debug this further within intellij?
I have the same issue while including the report plugin "maven-jxr-plugin" with IDEA 13, but other plugins are work well.
The plugin could be found in Central Repo, but not in local.
One solution is to move the declaration from report section to build section, then the downloading will be triggered, and the reporting still works.
I changed config intellij's config dirs in 'idea.properties' and found the 'idea' log file. The dependency problem went away as soon as I changed config dirs, no explanation, except that i didn't realize intellij was throwing errors until I ran 'idea.bat' at the command line. So - 1/ run from command line 2/ look into idea log file for unexplained problems

Error in POM.xml

I am trying to build the openNMS in eclipse helios using maven. After importing the source using "import existing maven project" i get the around 10k errors. Also i have some error in pom.xml itself, i thought fixing it could reduce the no of errors. The error in pom.xml is
maven-resources-plugin prior to 2.4 is not supported by m2e. Use maven-resources-plugin version 2.4 or later.
Iam referring to http://www.opennms.org/wiki/Eclipse_and_OpenNMS for building the openNMS
Iam using maven available at http://www.eclipse.org/m2e/download/
It would help if you told us which versions of Eclipse & m2eclipse you are using, and which version of OpenNMS you are trying to build.
If all else fails, you should be able to run the Maven build from the command line. In my experience, command line builds are always more reliable and predictable.
Also make sure that you are using the instructions that match the version of OpenNMS you are trying to build.
I have run the command mvn eclipse:eclipse from cmd line which downloaded the libraries in repository then i tried to import the same source directory into eclipse only to find 10k errors
That's not what I meant.
Get out of eclipse.
Get a command prompt.
Create a new directory somewhere the is not in your eclipse workspace.
Checkout the source code.
From the command prompt run "mvn install".
And you haven't answered the questions I asked above. If you don't want to answer, fine ... but don't expect us to be able to help you.
... and i get the error as Build Failure [INFO] There are test failures.
What has happened is that the unit tests have failed, presumably because something needs to be set up to enable testing. (Perhaps, the tests are trying to talk to a database?)
There are two solutions:
Find out what is causing the tests to fail, and fix it. The surefire reports may give you some clues, and there may be some developer documentation on the test setup.
Turn off the tests by adding -Dmaven.test.skip=true to the mvn command line; see this page.
It would also be a good idea to read the Maven documentation if you haven't done so already.
You cannot combine eclipse:eclipse with the m2eclipse support. You cannot use m2eclipse with a project that uses the old resource plugin.
If you want to use eclipse:eclipse, you must use NOT use the 'maven' import from eclipse. Use just 'import existing project'. If you want to use m2eclipse, don't use eclipse:eclipse.
I had this issue with the PDFBox source, with the parent pom for that project. I put this in the pdfbox/pom.xml (just to get it to compile in eclipse at lease, which is the only thing I wanted):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<executions>
<!-- had a process goal here that i removed because it was not compatible -->
</executions>
</plugin>

Categories