Eclipse/STS does not suggests autocompleting for JUnit code - eclipse

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.

Related

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.

Trouble running maven in eclipse

I have trouble running the project imported in maven.
I followed the following steps ->
go to Open File...→Import Project from File System, then choose your project1 directory. To compile your project, right click on the project name at the Package Explorer, select Run As, and then Maven install.
I get the error as shown in the pic.....I have installed jdk 1.6 though...any way how to resolve this???
Here's the complete pom
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.uta.cse6331</groupId>
<artifactId>cse6331-P1</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>CSE6331 Project #1</name>
<properties>
<hadoop.version>2.6.0</hadoop.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
</dependency>
</dependencies>
Please try adding below dependency
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/lib/tools.jar</systemPath>
</dependency>
Also ensure you refer to correct to JDK location not JRE (${java.home})
Please check eclipse is referring to JDK and not JRE.
In Eclipse, Navigate to Window -> Preferences
On the left hand pane, expand Java and you will find the "Installed JREs" entry

SpringBootApplication can not be resolved to a type error in Spring tool suite and maven

I have created the maven project in spring tool suite. I created the pom.xml with required dependencies but facing error as "SpringBootApplication can not be resolved to a type".
I have tried a couple of solutions like Maven -> Update Project..., Clean Project, deleted local repository directory of Maven (.m2), etc... also I tried creating another maven project but still the same error.
I think this is eclipse spring tool suite problem with maven.
Is there any solution like patch by eclipse or anything else?
Thanks in advance!
Pom.xml as follows
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
You did not add the correct dependencies.
You should add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
as a dependency (in <dependencies>) instead of spring-boot-starter-parent.
Parent just defines the versions but does not actually add any dependency (you use it as a <parent> in Maven).
If you have test, also add spring-boot-starter-test.
I would also suggest to use https://start.spring.io/ to generate a working Spring Boot base project (also available from STS in File->new->Other->Spring Starter project).
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
Copy/Paste it in your POM.xml. Update the Maven project and it will fetch the required JARs.

Package does not exist when using Maven

<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</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mavenproject1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When I try to import com.mongodb, I get a package does not exist error. I had to manually add the .jar file to make it work. How do I get Maven dependency to work?
Thank you
You have the maven coordinate correct, and the artifact does exist on maven central repository. So I strongly believe your maven settings had configuration problem causing it unable to fetch from central repository.
This commonly occur when you're behind a company internal repository such as nexus and it has stale index, or you set your ~/.m2/settings.xml to NOT lookup from the central repo.

maven "Please verify you invoked Maven from the correct directory" error in 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.