I am having this error message for all the imported packages "The import org..... cannot be resolved". and my Spring and Hibernate dependencies are not being resolved. I have tried multiple solutions to fix this error but nothing seams to work, below are the solution I've tried.
Maven => Update Project but same error. Also did => Force Update of Snapshots/Releases
I have also tried to Right-click on the project and choose Properties, and then Maven. Uncheck the box labelled "Resolve dependencies from Workspace projects", hit Apply, and then OK
Deleted my local Maven repo, the .m2 directory and Restarted Eclipse.
https://i.stack.imgur.com/LCUta.png
'''
<modelVersion>4.0.0</modelVersion>
<groupId>com.luv2code.springdemo</groupId>
<artifactId>spring-crm-rest</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<properties>
<springframework.version>5.0.6.RELEASE</springframework.version>
<hibernate.version>5.4.1.Final</hibernate.version>
<mysql.connector.version>5.1.45</mysql.connector.version>
<c3po.version>0.9.5.2</c3po.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${springframework.version}</version>
</dependency>
<!-- Add Jackson for JSON converters -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
</dependency>
<!-- C3PO -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>${c3po.version}</version>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- to compensate for java 9 not including jaxb -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<finalName>spring-crm-rest</finalName>
<plugins>
<!-- Builds a Web Application Archive (WAR) file from the project output
and its dependencies. -->
<plugin>
<!-- Add Maven coordinates (GAV) for: maven-war-plugin -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</build>
'''
You need as first step to run from terminal in your project root directory the mvn clean install command. In this way you will "install the package into the local repository, for use as a dependency". After that for sure you need to refresh your workspace and run a mvn update
A major problem is apparent from the picture you provided, but I'm not sure how you got it into this state.
By default, Maven projects will have a source directory at "src/main/java" and "src/test/java". Your source directory appears to be just "src", so it's finding classes in "main/java/com/..." so it wants the packages to start with "src.main.java.com...".
You appear to have overridden the settings in the .classpath file somehow. If you're using Maven in Eclipse, you should let the m2e plugin determine the classpath.
From what I can see, if you remove the "src" source directory and replace it with "src/main/java", it will more likely be able to compile your code.
Update:
To answer your question in the comment (this is too long for a comment):
Neither. I would suggest copying the project to a location outside of your workspace, if it isn't already outside of the workspace. If the project was already located outside of the workspace, now delete the project, but DO NOT delete the contents. If the project was located inside the workspace, as you've now copied it out, you can delete the project. At this point, go to the location where the project lies outside of the workspace, and delete the ".classpath" file from that location. Now, import the project back into Eclipse. If your project is conventional otherwise, this will "reset" it to a sane organization with respect to m2e.
Related
Today when I tried to install my maven project, I get an error due JDT dependencies and here is the report information:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
[ERROR] Failed to execute goal on project redundantcheck:
Could not resolve dependencies for project edu.fudan.selab:redundantcheck:jar:1.0-SNAPSHOT:
Failed to collect dependencies at org.eclipse.jdt:org.eclipse.jdt.core:jar:3.20.0 ->
org.eclipse.platform:org.eclipse.core.resources:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for
org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I tried to add 1.1.0 org.osgi.service:org.osgi.service.prefs to the project, but still can't solve this problem. To avoid dependency update, I specied almost every version of the dependencies, but still encounter this error today. Here is my pom.xml:
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.commands</artifactId>
<version>3.9.800</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.contenttype -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.contenttype</artifactId>
<version>3.7.900</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.filesystem -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.filesystem</artifactId>
<version>1.7.700</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.jobs -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.jobs</artifactId>
<version>3.10.1100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.resources -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.resources</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.core.runtime -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.runtime</artifactId>
<version>3.20.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.equinox.common -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.common</artifactId>
<version>3.14.100</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.osgi -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.16.200</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.platform/org.eclipse.text -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.text</artifactId>
<version>3.11.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.core.expressions</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.app</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.registry</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies>
Is there anyway to solve this problem?
EDIT: The issue is known by the project team and tracked as eclipse-equinox/equinox.bundles#54 on GitHub.
The dependency:
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.0</version>
Which is one of your transitive dependency, references this dependency in its dependencies list:
<dependency>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Source: org.eclipse.equinox.preferences-3.10.0.pom on maven central.
It is a mistake. As Maven tells you, this does not exist:
Cannot resolve No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range.
It should have been:
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
<version>[1.1.0,1.2.0)</version>
</dependency>
Which exists (note the different groupId).
Because you are not fixing the dependencies you are consuming in your project, and because the dependencies are using version ranges, suddenly you got a new version.
By the way as beingnurd has noted, there is now the newer version 3.10.1 of org.eclipse.equinox.preferences where this wrong dependency is fixed (see org.eclipse.equinox.preferences-3.10.1.pom).
If you continue to use always the newest dependency of the compatible range, the problem will be solved for you.
Now if we take a step back:
You are trying to use following JDT version:
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.20.0</version>
</dependency>
This corresponds to the Eclipse Version 2019-12 (also called 4.14 internally).
Your problem is that the eclipse projects (org.eclipse.jdt.core and all the dependencies) are using version ranges.
If you look at the org.eclipse.jdt.core dependencies declarations:
org.eclipse.platform:org.eclipse.core.resources:[3.12.0,4.0.0)
org.eclipse.platform:org.eclipse.core.runtime:[3.13.0,4.0.0)
org.eclipse.platform:org.eclipse.core.filesystem:[1.7.0,2.0.0)
org.eclipse.platform:org.eclipse.text:[3.6.0,4.0.0)
If you don't do anything, Maven always takes the latest:
Today (June 2022) this would be:
org.eclipse.core.resources: 3.16.100
org.eclipse.core.runtime: 3.24.100
org.eclipse.core.filesystem: 1.9.300
org.eclipse.text: 3.12.0
When the library was published (December 2019) this was:
org.eclipse.core.resources: 3.13.600
org.eclipse.core.runtime: 3.17.0
org.eclipse.core.filesystem: 1.7.600
org.eclipse.text: 3.10.0
And of course this is recursive, you need to do this for all the dependencies.
Letting Maven choose always the latest is problematic:
It prevents you creating reproducible build, because the dependencies picked by maven depends from what is available on maven central on that day.
You need to solve conflicts.
You are potentially the first trying out a combination.
This is why I always use a set of projects that were released together. By the way this is also how the Eclipse project itself is doing it (by using P2 update sites and target platform).
I am publishing Maven BOM files to fix the versions: ECentral project
This is how you can do it:
<repositories>
<repository>
<id>ecentral</id>
<url>https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<!-- no version needed here, because it is defined in the BOM -->
</dependency>
</dependencies>
Because I ran into this problem today too, but via plugin sub-dependency, my temporary solution is to download the regular org.osgi:org.osgi.service.prefs:jar:1.1.2 and install it in the local repository as org.osgi.service:org.osgi.service.prefs:jar:1.1.2.
You can exclude the dependency like this :
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.24.0</version>
<exclusions>
<exclusion>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
</exclusion>
</exclusions>
so the reason for this failure is dependency
<groupId>org.osgi.service</groupId> <artifactId>org.osgi.service.prefs</artifactId>
but the group org.osgi.service doesn't exists, instead it is only org.osgi
so dependency should look
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
I have got the same problem today in our SpringBoot project 1.5.25 with org.hibernate:hibernate-tools:jar:5.0.6.Final
The error message as follow:
# Failed to collect dependencies at org.hibernate:hibernate-tools:jar:5.0.6.Final ->
# org.eclipse.jdt:org.eclipse.jdt.core:jar:3.12.2 ->
# org.eclipse.platform:org.eclipse.core.resources:jar:3.11.1 ->
# org.eclipse.platform:org.eclipse.core.expressions:jar:3.5.100 ->
# org.eclipse.platform:org.eclipse.core.runtime:jar:3.12.0 ->
# org.eclipse.platform:org.eclipse.equinox.preferences:jar:3.10.0 ->
# org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0): No versions available for org.osgi.service:org.osgi.service.prefs:jar:[1.1.0,1.2.0) within specified range -> [Help 1]
I use the private nexus, to resolve this problem, i added a proxy maven2 (maven-ecentral) repo pointed to https://raw.githubusercontent.com/jmini/ecentral/HEAD/repo , thanks #Jmini
then added the follow lignes in the pom.xml
<dependencyManagement>
<dependencies>
<dependency>
<groupId>fr.jmini.ecentral</groupId>
<artifactId>eclipse-platform-dependencies</artifactId>
<version>4.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>ecentral</id>
<url>https://nexus.xxxx.xxx/repository/maven-ecentral/</url>
</repository>
</repositories>
Reload your project with IDEA, it should work.
Another solution is using exclusions
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>${hibernate-tools.version}</version>
<!-- exclure the old org.eclipse.platform -->
<exclusions>
<exclusion>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- the 3.10.1 org.eclipse.platform fixed the pb -->
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.equinox.preferences</artifactId>
<version>3.10.1</version>
</dependency>
Even I have been facing this problem since today, it was working fine till yesterday.
Finally what I found was that pom of org.eclipse.equinox.preferences:3.10.0 group id mentioned as org.osgi.service, but the artifact is located in repo1.maven.org at org/osgi, there is no service folder in it.
I changed dependency group id to org.osgi in the pom of org.eclipse.equinox.preferences and then it worked.
--EDIT--
I can see a new version of 3.10.1 added in repo which has the group id corrected to org.osgi instead of org.osgi.service
I ran into this problem with a maven plugin (net.revelc.code.formatter). We use it from another maven plugin that generates code. Since it is just a formatter for generated code, my solution was to drop the usage of the formatter plugin. Obviously I couldn't use the above solutions, because I don't want to fork the formatter code.
I'm trying to use Unirest in my program but I keep getting this error java.lang.NoSuchMethodError: com.google.gson.Gson.newBuilder()Lcom/google/gson/GsonBuilder;
I have tried using different maven versions of Gson but I still continue to get this seror
Edid added my pom.xml, I tried deleted my .m2 but I am still having this problem
<dependencies>
<!-- https://mvnrepository.com/artifact/com.konghq/unirest-java -->
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.7.00</version>
<classifier>standalone</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>Spigot8</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/spigot-1.8.8-R0.1-SNAPSHOT-latest.jar</systemPath>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>compile</scope>
</dependency>
</dependencies>```
Could be a conflict between the GSON versions in your POM file versus what is in your container (Tomcat/JBoss) etc. Inspect the JARS in WEB-INF/lib. If there are two different versions, then delete the one which is not the same as the one currently in your maven project's POM file. I had a similar issue - my project was using gson-2.6.3.jar but a conflicting gson-2.1.jar also existed in WEB-INF/lib. I deleted gson-2.1.jar and this resolved my problem
This issue is possibly due to conflicts in Gson versions.
Go to your repository if you are on windows:
C:\Users\User_name.m2\repository\com\google\code\gson
or on Mac:-
/.m2/repository/com/google/code/gson
Delete all the existing folders.
Now, add below maven dependency in your pom file:
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
Re-build your maven project and try to run.
It seems like a dependencies issue.
Please make sure your dependencies are correct. Unirest 3.7.00 uses Gson 2.8.6
https://mvnrepository.com/artifact/com.konghq/unirest-java/3.7.00
Also, if you don't use Gson separately you don't need to specify it. Just add a dependency for unirest-java as it's described in Maven repository:
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.7.00</version>
</dependency>
In Eclipse, when I go to myProject -> right click -> Run As -> Maven build, I am getting multiple errors in the console outlining that certain packages does not exist, like:
javax.ws.rs does not exist
javax.ws.rs.core does not exist
javax.servlet does not exist
javax.servlet.http doest not exist
Although in my pom.xml, I have provided those dependencies:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs</artifactId>
<version>1.0</version>
</dependency>
etc
under
<dependencyManagement><dependecies>
tags (don't have any errors in pom.xml).
I do also have proxy settings configured in settings.xml file, and this file is properly linked.
I've also got these jars included locally to WebContent\WEB-INF\lib folder and added to the classpath (I can run my REST service on tomcat, the error "package does not exist" appears only when I am trying to use Maven build".
The reason I need that I want to generate and deploy a .war file.
How I can solve this? Is there a war to force Maven look in local libraries instead?
If you have:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
then you need to have a separate:
<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs</artifactId>
</dependency>
</dependencies>
section.
Typically you would define dependencyManagement in a parent pom.xml file and then use the second dependencies fragment in child pom.xml files. This ensures that all your modules depend upon the same consistent artifacts.
i followed this spring-mvc-tutorial using eclipse, but after i call Maven / Update Projects my WEB-INF/lib directory remains empty.
this is how my project explorer looks:
i also see no mistake in my Deployment Assembly settings:
this is the pom.xml file i use:
<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>CrunchifySpringMVCTutorial</groupId>
<artifactId>CrunchifySpringMVCTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
i even switched to a new workspace as suggested in this link, but nothing helped
EDIT:
when i start the server i get the error:
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Eclipse virtually hides the files from the view that displays the WEB-INF/lib folder in a Maven-managed Dynamic Web-Project project. As your first screenshot indicates, the "Maven Dependencies" library entry has been successfully added to your classpath in the background by Eclipse - it contains every dependency referenced in your pom.xml.
The intention behind this behavior for that is/might be: You - as a developer - are not supposed to copy any .jar files manually to WEB-INF/lib, cause that way you would kind of cheat around the idea behind a (Maven-) managed project.
In a certain way, this makes sense as Maven performs any dependency management for you and thus resolves and "bundles" any third-party (or your own) artifacts.
If you run a mvn with the goals clean package (or even: clean install) it will produce a .war file for you in the "target" folder of your project. If you extract that .war file you should find a WEB-INF/lib folder that contains all dependencies bundled into your deployable artifact.
I think it is correct.
Libraries are copied into target after build, not into project itself.
Also Step 8 in the tutorial you pasted shows the same (empty lib folder)
I have maven project. Maven build complete SUCCESS. But i can't make this project.
[INFO] BUILD SUCCESS
Project contains one module. Idea can't see dependencies.
Error:(3, 38) java: D:\Dropbox\Programming\java\spring\springBook\src\main\java\ch14\validator\ContactTestValidator.java:3:
package org.springframework.stereotype does not exist
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>springBook</groupId>
<artifactId>springBook</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Shared version number properties -->
<properties>
<org.springframework.version>3.2.3.RELEASE</org.springframework.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!--для валидации бинов необходима-->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<!--Spring Data JPA использует его - добавим и пользуемся-->
<!--API для работы с датами-->
<!--ch14 validator-->
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<!--ch14 validator-->
<!--API интерфейса JSR-303-->
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<!--ch14 validator-->
<!--API, которая поддерживает интерфейс JSR-303 - BeanValidation-->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
</dependency>
<dependency>
<!--для валидации. (#Type...)-->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.2</version>
</dependency>
<!--Spring framework-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
<build>
<finalName>springBook</finalName>
</build>
</project>
Could you help me? Unfortunately, I can't add screenshots..
There are screenshots:
http://screencast.com/t/iNaWO9gy
http://screencast.com/t/iBGTyMpgH
Project settings - Libraries - empty;
reimport didn't help;
Do the following steps:
Find your pom.xml in your files
Right click on it --> Maven --> Import
Wait for the project to load :D
Press ctrl+alt+shift+s (This opens the Projects window.)
Go to libraries and see if they are empty (they shouldnt)
If they are post your full pom.xml please so I can see the problem
If you still have a problem got to File --> Invalidate Caches
/Restart
Go to maven and Reimport All Maven Projects
Option Maven -> Reimport
should force Intellij to reload all dependencies. Alternatively, as mentioned in comments you can click the Reimport All Maven Projects button in Maven Projects view.
In my case, I had my own apache-maven-3.5.2 folder and a misconfiguration created my problem. Maybe it's your case too:
In rush, I set the local repository to C:/my/folder/apache-maven-3.5.2/settings.xml, but it must be a folder so Maven didn't allow me to download the dependencies. Then I changed the default (in the picture) and it worked.
Open the module dependencies (press F12 on the module), go to Modules -> Dependencies and make sure maven imports are part of the of this.
Try to import the project from sources, if this answer didn't help you.
The following worked for me.
Deleted the maven dependency from my local repository
mvn clean install downloaded the dependency again
File --> Invalidate Caches/Restart
I still saw the compilation error
on my mac, I hit option + enter, intellij asked me to add the jar to classpath
build -> make project
I had faced the same problem, and the issue was small. I had changed the location of settings.xml file of maven and Intellij was picking up the default from C:\users\.m2\settings.xml
So point your maven settings.xml to the correct file as below:
File--> Settings--> Build, Execution, Deployment--> Maven
then on the right window, override "User settings file" to the settings.xml where you have in your local disk.
If you have installed maven in a non-default location then this file you can find in:
\apache-maven-3.2.3\conf\settings.xml
Right click on pom.xml and click Add as Maven Project