Eclipse Maven dependency jar grayed out, can't import classes from it - eclipse

I'm helping a friend configure a maven project with m2eclipse for the first time. We're both pretty unfamiliar with it and are encountering an issue where even though a dependency jar is showing up with packages in it under "maven dependencies" in the Project directory, if we try to import anything from any of that jar's packages, it can't find the class.
I noticed that the jars that are having issues are gray and not as opaque as the rest of the jars that are working.
What's strange is if you hover of the class name in the import, it shows a brief description of the class (from the documentation in the jar!) but it won't let me import it. All the other maven dependencies can be imported fine. Any ideas? We can't seem to even find what the darker icon means.
Also, the pom.xml is dead simple:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.something.portal.test</groupId>
<artifactId>PortalFrontEndTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PortalFrontEndTests</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Selenium -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I'm not sure what I'm missing here

open your pom.xml file
check for the name of the grayed out jar file
change
<scope>test</scope>
to
<scope>compile</scope>

I found the issue. It was because I had the class in the source directory instead of the test directory and both of the maven dependencies had been marked as "Visible only to test"

I had the same problem when i used the <scope>test</scope> in the maven pom.
It seems as if the newer Eclipse/Java versions do have a new Attribute :
<classpathentry kind="src" output="target/test-classes" path="src/test/java/...">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
This should be enabled in the Java Build Path Settings:
Image showing "Containts test sources" option from build path menu
After enabling this i got rid of all the compiler errors.

check for your dependency scope in POM file
compile, provided, system and test these were the available test
test -> compile would change your dependencies from grey to white.
If your dependency is for test scope then that dependency is not available for normal use in application whereas compile scope sets that dependency in class path of your project.

I am not sure on the grayed out part. If this is the feature because it suggest that Testing class should be under /test rather /src.
However, solution to your problem is scope of plugin, change it to compile and you will be good to go.
i.e. replace test with compile:
<scope>test</scope>
<scope>compile</scope>
That's it. you will not get any error for import testing packages.

Just removing the Scope will work. I tried as the following:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.0-M1</version>
</dependency>

I am also faced the same problem
set scope to compile or remove scope
open maven dependencies
right click on dependency and click download resources

Related

Cannot resolve symbol 'owasp', import error in intellij

I want to use ESAPI in my project and have added following dependency in the pom.xml
pom.xml with dependency:
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.5.0.0</version>
</dependency>
But when I import org.owasp.esapi.* intellij give me warning as shown in image.
I want to use ESAPI logger to prevent CRLF injection possibilities in log statements.
My current project uses slf4j.Logger
I am very new to this ESAPI and OWASP and have never used it and have tried from here
https://github.com/ESAPI/esapi-java-legacy/wiki/Using-ESAPI-with-SLF4J#configuring-esapi-to-use-slf4j
Please tell me if im doing something wrong and how to correctly use ESAPI in project.
Hmm. What JDK are you using with IntelliJ? Java 8 or later is required as of 2.4.0.0. That's the only thing that I can think of that would cause this behavior. Looks okay otherwise. Did you check if the esapi-2.5.0.0.jar got pulled down? Because it's either not finding that or it's not compatible with the Java version that your IntelliJ IDE is using.
Well i found that I was adding this dependency in <dependencyManagement> tag instead of <dependencies> tag, that's why it wasn't downloading from the repository.
Previous:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.5.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
after fix:
<dependencies>
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.5.0.0</version>
</dependency>
</dependencies>
Whats the difference in <dependencies> and <dependencyManagement> please refer this Differences between dependencyManagement and dependencies in Maven

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.

Error deploying Spring project to Weblogic [duplicate]

i am using spring 3.1.0.RELEASE, and my servlet container is tomcat 7 and my IDE is eclipse indigo
and the jar spring-webmvc-3.1.0.RELEASE.jar which contains the DispatcherServlet
exists in the lib folder, and yet when running the application, i am getting the exception:
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:126)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
please advise why i am getting this exception, and how to fix it.
EDIT: following are my configuration files:
1- .springBeans:
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.9.0.201203011806-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/main/webapp/WEB-INF/checkout-servlet.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
2- web.xml:
<web-app>
<display-name>Checkout</display-name>
<servlet>
<servlet-name>checkout</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>checkout</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
3- checkout-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.myapp"/>
<bean id="myService" class="com.myapp.MyService"/>
</beans>
also when trying to access any page in the application, i get the exception:
HTTP Status 404 - Servlet checkout is not available
type Status report
message Servlet checkout is not available
description The requested resource (Servlet checkout is not available) is not available.
Apache Tomcat/7.0.22
You need to add the "Maven Dependency" in the Deployment Assembly
right click on your project and choose properties.
click on Deployment Assembly.
click add
click on "Java Build Path Entries"
select Maven Dependencies"
click Finish.
Rebuild and deploy again
Note: This is also applicable for non maven project.
Two possible answers:
1- You did not include spring-beans and spring-context jars in your lib.
If you are using maven (which will help a lot) those two lines will be enough
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
2- The necessary jars are in your classpath but are not deployed on tomcat.
I had the same problem with Idea Intellij and Spring 4. I fixed the problem and I wanted to share the answer with you.
I use tomcat 7 / idea intellij 13 / spring 4.
pom.xml dependencies:
<properties>
<spring.version>4.0.5.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
enter code here
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
In idea Intellij, you need to go to File -> Project Settings -> Artifacts.
Then
clean -> rebuild the project -> build the artifact, and everything will be ok.
This solves the problem for me. It's easy and pretty simply explained.
Step 1
Right click on project
Click on Properties
Step 2
Click on Deployment Assembly Tab in the
Click Add...
Step 3
Click on Java Build Path Entries
Step 4
Click on Maven Dependencies
Click Finish button
Step 5
Redeploy Spring MVC application to Tomcat again
Restart Tomcat
List item
classnotfoundexception
i found that in the deployment assembly, there was the entry:
[persisted container] org.maven.ide.eclipse.maven2_classpath_container
i removed it, and added the maven dependencies entry, and it works fine now.
If all of these advice doesn't work, you should re-create your Server (Tomcat or like that). That solved my problem.
Include below dependency in your pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>{spring-version}</version>
</dependency>
I was facing the same Issue. When I saw into maven repository .m2 folder(....m2\repository\org\springframework\spring-webmvc) in my local I found two 3.2.0.RELEASE folders. SO I removed one.
Then I went to project, right click->properties->deployment essembly-> add maven dependencies.
clean build and then restart the server.
Then the DispatcherServlet got loaded.
Go to properties of Project which your working
Choose the Deployment Assembly menu and Click on add button
opt the Java Build Path Entries and Click on Maven Dependencies
Build the project and run
In my case I get this trouble after using the maven's update project utility.
I tried all the workarounds you suggested but nothing seemed to work.
At the end the solution was simply to remove the project from the server to ensure that it was clean, and add it again. Then it works, I hope this solution could help any of you.
You can use GlassFish server and the error will be resolved. I tried with tomcat7 and tomcat8 but this error was coming continuously but resolved with GlassFish. I think it's a problem with server.
These are the results with tomcat7:
Here are the results with GlassFish:
right click on your project and choose properties.
click on Deployement Assembly.
click add
click on "Java Build Path Entries"
select Maven Dependencies"
click Finish.
It may be useful for someone, so I'll post it here.
I was missing this dependency on my pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
I solved by following these steps:
Right click in the project > Configure > Convert to Maven project
After the conversion, right click in the project > Maven > Update project
This fixes the "Deployment Assembly" settings of the project.
Move the jar files from your classpath to web-inf/lib, and run a new tomcat server.
I found a simple solution,
Simply add your jars inside WEB-INF-->lib folder..
I had this same issue in WebSphere, but couldn't find a solution even though I verified the Spring dependencies were there and it ran in tomcat just fine. I ended up uninstalling the application and was still getting the error so I think WebSphere was hanging onto some corrupt instance.
To fix the issue I had to reinstall the application, stop it, uninstall it and then reinstall it.
For me it was a mistake in the pom.xml - I'd set <scope>provided<scope> on my dependencies, and this was making them not get copied during the mvn package stage.
My symptoms were the error message the OP posted, and that the jars were not included in the WEB-INF/lib path inside the .war after package was run. When I removed the scope, the jars appeared in the output, and all loads up fine now.

eclipse maven dependencies pom file

Hi does anybody know where do i need to setup the mahout.version property in order for eclipse to get the latest version of the dependency?
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>${mahout.version}</version>
</dependency>
if you have a super pom or parent pom.xml you can make the properties like this :
<properties>
<mahout.version>0.9</mahout.version>
</properties>
Please replace following in your pom.xml of maven build.
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.8</version>
</dependency>

Maven does not automatically download dependencies

I'm a starter for Maven. I pulled a java maven project from Bitbucket. When compiling the prject Eclipse said "8/6/12 1:39:05 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile":
Maven console:
8/6/12 1:39:03 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile
8/6/12 1:39:05 PM EST: Missing artifact com.tinkerpop.blueprints:blueprints-core:jar:1.0:compile
but when I check the pom.xml file, it is already there in the dependency list, only the Type and Scope fields are empty. Seeing the errors, I try to add this dependency by myself. And it showed like this:
The #1 question is, Why for 1.0 version, blueprints-core only have a .pom file not a .jar file? Does this mean in the remote repository they don't provide the 1.0 version any more? (I found the codes in the project reply on 1.0 version instead of 2.0 version of this Blueprint framework)
The #2 questions is, under what circumstances Maven will not automatically download the jar files for the dependencies added?
This is the original pom.xml file:
<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">
<parent>
<groupId>edu.qut.cs</groupId>
<artifactId>qut-recommender</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../qut-recommender/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rcmd-common</artifactId>
<packaging>jar</packaging>
<name>QUT Recommender Common Library and Utilty</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.7.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-ext</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jgrapht</groupId>
<artifactId>jgrapht</artifactId>
<version>0.7.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
</project>
The POM and Jar files of 1.0 version exist. The following picture is the directories and files in the folder of "C:\Users\n8275441.m2\repository\com\tinkerpop\blueprints". BTW, I pulled this project from Bitbucket repository. Is it possible that those 1.0 version files came along with the project in Bitbuckdet?
Based on your information and after checking maven central the problem is based on the version you have selected. Maven Central contains only a version 1.2, 2.0.0 and 2.1.0 but not a version 1.0.
Furthermore if a dependency is given without scope like in your pom:
<dependency>
<groupId>com.tinkerpop.blueprints</groupId>
<artifactId>blueprints-core</artifactId>
<version>1.0</version>
</dependency>
this means default scope which is "compile" (as in the sense of convention over configuration). I would simply suggest to change the version to 2.0.0 or 2.1.0 which should solve the problem.
If you check compiling such project i would suggest to do the first try on command line and not in Eclipse.
If you're wondering what Maven Central offers, mvnrepository.com is your friend.
In this case, there is no 1.0 version: http://mvnrepository.com/artifact/com.tinkerpop.blueprints/blueprints-core
Which leads to the interesting question why m2e reports a POM file for it. I suggest to have a look on your hard disk if the POM file really exists. You can find it (or not) in C:\Users\n8275441\.m2\repository\com\tinkerpop\blueprints\1.0\blueprints-core\
As for question #2: Maven (and m2e as well), will try to download a release (i.e. something that doesn't have SNAPSHOT in the version) only once. If the download fails, Maven will note that and never try again since it assumes that the upstream repositories (Maven Central, for example) heed the Maven rules (so if a repo doesn't have something, it won't have it tomorrow).
For snapshots, Maven will try to download them once per day to get a good balance between keeping you up to date and not wasting your time waiting for some download.