maven "Please verify you invoked Maven from the correct directory" error in eclipse - eclipse

I created a java project in eclipse. The project location is /home/vikas/code/primeNumberWorkSpace/primeNumber.
I linked the source and pom files from other locations (/home/vikas/code/primNumber/src/ and /home/vikas/code/primeNumber/pom.xml)
When i issue 'clean install' command from the eclipse, it gives the following error,
[ERROR] The goal you specified requires a project to execute but there
is no POM in this directory
(/home/vikas/code/primeNumberWorkSpace/primeNumber). Please verify you
invoked Maven from the correct directory. -> [Help 1]
How to resolve this.
the pom file is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>main.java.com.simpragma.primenumber</groupId>
<artifactId>prime-number</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>

You might have tried setting the AutoRun registry key for Command Processor to change where cmd.exe has its starting location...
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\AutoRun
Check this value, as a CD in this autorun will change the default location of all cmd.exe that are run on the system. Which is wonderful, but it apparently breaks something in maven workflow.
Deleted my AutoRun value and this issue went away for me.

I was also having this issue with maven projects within MuleSoft Anypoint Studio 6.4.4, which is based on Eclipse 4.5.2. By removing the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor\AutoRun value the issue went away.
Thanks for your answer Dave Horner.

Related

Eclipse/STS does not suggests autocompleting for JUnit code

I have a simple project configured with the pom.xml file that I copy below. The problem is that Spring Tool Suite 4.9.0.RELEASE does not suggests automplete for classes nor methods from JUnit library. If I write code like this one:
Assert.assertEquals(text_1, text_2);
It compiles and works, but if I put the mouse cursor right after the dot after Assert and press Ctrl + . "No default proposal" message is shown. With other classes out of JUnit autocomplete suggestions works fine.
I checked configuration as proposed in other questions but none fixes this issue.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.microservices</groupId>
<artifactId>Module</artifactId>
<version>1.0.0</version>
<name>module</name>
<description>Module tools</description>
<properties>
<springframework.version>2.1.4.RELEASE</springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>
${project.name}
</finalName>
</build>
</project>
Removing .metadata and .settings folders along with .project and .classpath files seems to have resolved the issue (in addition to reboot Eclipse and import projects again).
This way I also lost launch configurations, etc.
EDIT: As howlger suggests removing .metadata folder is serious risk. Do it on you own responsability.

Gatling Error: Could not find or load main class Engine

I installed the latest IntelliJ idea, latest maven 3.6.3, Java 1.8, set the JAVA_HOME / JRE_HOME env variables. Then generated a Gatling project using mvn archetype:generate -Dfilter=gatling. In summary, I followed the instruction here. I have installed the Scala plugin for IntelliJ idea as well. When I try to run the Gatling engine by right-clicking on the Engine class,
I am getting below error. can someone tell me what's going on here? I tried all the suggestions online, but no luck so far. Thanks
"C:\Program Files (x86)\Java\jdk1.8.0_221\bin\java.exe".....
Error: Could not find or load main class Engine
Process finished with exit code 1
Here is my POM file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.gatling</groupId>
<artifactId>pert-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<gatling.version>3.2.1</gatling.version>
<gatling-maven-plugin.version>3.0.3</gatling-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-app</artifactId>
<version>${gatling.version}</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
<artifactId>gatling-recorder</artifactId>
<version>${gatling.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
David MontaƱo... after manually marking src/test/scala as Test Sources Root, I got "Error:(11, 18) illegal cyclic inheritance" as mentioned by Rasika
I just found that scala 2.13.1 is not compatible with gatling. I removed scala 2.13.1 from global libraries list and added scala 2.12.10. Tests working fine now. Here are the steps
Right click project folder in IntelliJ and choose 'Open Module Settings'
Under 'Platform Settings' select 'Global Libraries'
Here, remove scala-sdk-2.13.1 and add scala-sdk-2.12.10
Rebuild the module
It worked for me when I manually marked the src/test/scala as Test Sources Root and rebuild the project.
Mark as Test Sources Root
It should be picked up automatically by IntelliJ but it wasn't the case.
Tied both :
marked the src/test/scala as Test Sources Root and rebuild the project.
Mark as Test Sources Root
And
Under 'Platform Settings' select 'Global Libraries'
Here, remove scala-sdk-2.13.1 and add scala-sdk-2.12.10
then works.

m2e does not import dependency from profile

I have come up with this simplified test case of the problem I am experiencing with the very big project I am working on. The important bit is to have some code and its dependency activated only in a specific profile. Here is the POM file to demonstrate it:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mytest</groupId>
<artifactId>project1</artifactId>
<version>1.0</version>
<properties>
<src.dir>src/main/java</src.dir>
</properties>
<build>
<sourceDirectory>${src.dir}</sourceDirectory>
</build>
<profiles>
<profile>
<id>fox</id>
<properties>
<src.dir>src/fox/java</src.dir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
And in the directory src/fox/java/project1 relative to the POM I have got this simple class using the jar dependency from the pom:
package project1;
import org.apache.commons.lang3.BooleanUtils;
public class C1 {
public static void main(String[] args) {
System.out.println(BooleanUtils.isTrue(Boolean.FALSE));
}
}
I can build the above project with this command without a problem:
mvn -Pfox package
But I don't know how to properly import this Maven project into Eclipse. The abnormality can be seen if I open its POM in Eclipse and observe it in the "Dependencies" tab. The commons-lang3 jar file does not show there by default. Only if I click on the button "Show inherited dependencies" it comes up with the icon in front of it presumably denoting it was "inherited".
POM dependencies
But I don't understand where it could be "inherited from. I also want to add the it shows as a "normal" dependency if I don't use the profiles.
I did specify the profile "fox" at the import time and verified that it was selected in Eclipse. I also tried "Update project" option from Eclipse which did not make a difference.
This in itself would not bother me if it was't a symptom of the bigger problem I am experiencing. In our application a project like in the example is a dependency of another project with WAR packaging. And when such project is deployed to Tomcat running under Eclipse the jar from the picture is not included into the deployment description and naturally the application does not run.
Profiles in dependencies are not activated
https://issues.apache.org/jira/browse/MNG-1388

Converting to Maven Project from Java Project

I have installed m2eclipse plugin. I tried to convert a java project into a maven project.Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.test</groupId>
<artifactId>SpringExample</artifactId>
<version>1.0.0</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<dependencies>
<dependency>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
<version>2.1</version>
</dependency>
</dependencies>
</project>
When I clicked on configure and converted it into maven project , I found out that 2 folders have been generated bin & target and all the class files are in bin folder, target folder is empty & jar was not created.
This is the first time I'm trying to use maven and what I understand is that there should have been 2 folders generated src and target.
I can't figure out what went wrong(I did not get any error).
I am using eclipse juno ,I have installed m2e version 1.3.1.x
I would recommend that you read Maven in 5 minutes.
Converting the project will only generate the pom ("This wizard creates a new POM (pom.xml) descriptor for Maven.").
If you want to generate an project with the folder structure you have to use an maven archetype.
Example:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=com.test -DartifactId=SpringExample -Dversion=1.0.0 -Dpackaging=jar -DinteractiveMode=false
You have to put your code under src/main/java. Tests should be under src/test/java. Your output is in target directory. Bin is generated by Eclipse not maven.
More about directory structure here

Eclipse with maven workspace dependency - packaged war contain folder instead of jar

I'm using Eclipse Kepler SR2 with m2e.
I have a web project that depends on a jar.
When I use "Run as -> Maven Build..." with goal package and "Check Workspace artifacts" is checked, then the lib folder in the target contains a folder with the name of the dependency jar, instead of the jar itself. The packaged war also contains a folder instead of a jar. However, when deploying to tomcat with m2e, the jar is deployed correctly.
I use maven-war-plugin version 2.4.
This is my WAR pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
</project>
And this is the artifact coordinates of the dependency jar:
<parent>
<groupId>com.modelity.loans</groupId>
<artifactId>loans-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-core</artifactId>
<packaging>jar</packaging>
I've looked at the debug output of the maven package goal. When the war plugin is processing the jars, it says
[DEBUG] Processing: loans-core-0.0.1-SNAPSHOT.jar
without indicating the jar has been copied.
Later on in the log I see:
adding directory WEB-INF/lib/loans-core-0.0.1-SNAPSHOT.jar/
I've tried both embedded maven (3.0.4) and external maven (3.0.5).
My colleague uses kepler SR1, and experience the same problem.
I think I've covered it all. Would be happy for some advise, couldn't find any reported bug about it.
Thanks,
Lior
Try installing the jar as its own maven-controlled artifact:
mvn install:install-file -Dfile=my.jar -DgroupId=com.mycorp -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
And then define it as a maven dependency for your war
now we have 2018 and the problem still exists in eclipse v2018-09. Maven Dependencies which exist in the workspace are exploded into WEB-INF/lib folder.
Found this old bug report https://issues.jboss.org/browse/JBIDE-22157 regarding this behaviour.
Solution is to disable "dependency resolution from workspace projects" in maven project settings.
regards,
Markus