Unable To Use ch.qos.logback.classic Classes - java

I have spring project setup on Intellij Idea 2016.2 using Maven. For some reason I cannot import or use any class present in ch.qos.logback.classic package. I tried to invalidate cache, re-import maven dependencies.
For example with
import ch.qos.logback.classic.Level;
the IDE says 'cannot resolve symbol Level'. When compiling from command line it says 'package ch.qos.logback.classic does not exist'. Any suggestion what might be wrong?
Update - found the issue. I had set dependency scope to compile. Updating this fixed the issue.

Have you added the ch.qos.logback:logback-classic Maven artifact in your dependencies?
You should have something like that in your pom :
<dependencies>
...
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
...
<dependencies>

Related

Unable to import com.auth0.jwt

I unable to import Java jwt 3.10.0. in my spring project. Actually I was trying before version 3.15.0 but it was giving me an error in pom.xml
"Dependency 'com.auth0:java-jwt:3.15.0' not found"
anyway I then move with version 3.10.0 which is accepted in pom.xml, but it doesn't importing in project, although I've many updated Maven, restart Intellj.
Grateful if anyone can advise.
Dependency in pom.xml
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.10.0</version>
</dependency>

The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files

I am following the tutorial at spring.io to build a spring app using spring boot.
I can get the program to run perfectly on one computer.
When I try on a different computer I get the following error
The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
I have tried deleting and adding my JRE Systems Library (JDK 1.8), as well as cleaning and updating the project using maven, and even deleting and re-importing the entire project. All of these methods have shown no success.
My 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<groupId>test.api</groupId>
<artifactId>api.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api.test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<finalName>api.test</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The class that is giving me the error is the HelloWorldConfiguration.java class
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HelloWorldConfiguration {
public static void main(String[] args) {
SpringApplication.run(HelloWorldConfiguration.class, args);
}
}
Any help would be greatly appreciated. Thank you.
Your Maven cache is corrupted on the second machine. The JAR can't be opened, that's why you get this exception.
You can fix that by running this command on the second machine for that project:
mvn dependency:purge-local-repository
If that doesn't work, try remove your local repo on that machine (~/.m2/repository/org/springframework) and run mvn package again.
I also faced the same issue before. Some dependency corruption might have occurred. You can purge and re-resolve the dependencies.
For that :
go to the project location where the pom.xml is present.
open a command prompt there and enter the command below :
mvn dependency:purge-local-repository -DreResolve=true
I had the same issue and I followed these steps to fix it:
1. Close Eclipse
2. Remove all files inside the repository folder .m2/repository
3. reopen Eclipse and update your Maven project
I had the same problem. I resolved this my deleting the local repository directory of Maven (.m2) on your local computer. It resolved the problem for me.
Find out the version of spring-context your project uses:
(in Eclipse : Project Explorer -> [your project] -> Maven Dependencies)
or
mvn dependency:tree
Lists all dependencies for your project
Delete the folder org/springframework/spring-context/5.0.9.RELEASE from your maven repository .m2/repository. Assuming 5.0.9.RELEASE is the spring-context release version.
this conflict occurs, because some of your dependencies have corrupted.follow this:->
for removing this conflict just go in to your .m2 folder open repository and delete all the files from that folder. and now open your project go in debug do maven clean and after cleaning and all downloading just update your maven projet. and your conflict will have been going to resolve.
I too have same problem, I resolved by removing .m2/repository/org folder,later did maven updated form STS.
Add bellow dependancy
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.7.RELEASE</version>
</dependency>
It may be because some of the dependency is not resolved correctly.
You can try to change/de-grade version of "spring-boot-starter-parent" to other working project in your local.
E.g. mine Error gone by setting "spring-boot-starter-parent" to "1.5.9.RELEASE" from "2.3.0.RELEASE" (that version was working for other project).
My answer is too late, but maybe helps others.
I had the same issue while using Eclipse IDE with spring project that I made using start.spring.io. The way I fixed it:
Right-click on your project.
Runs As.
Maven Install.
For me ,first answer only works when open the child project as a new project in a new window .
You can try delete main.iml or xxx.iml in your child project src\main\main.iml.
That works for me
EDIT: dont worry, main.iml is auto generated by idea
I also faced the same issue and to resolve this I downloaded the jar and added as an external jar.
Here is the download link: http://www.java2s.com/Code/Jar/o/Downloadorgspringframeworkcontextjar.htm

intellij not finding maven imports from third party repository

My pom.xml includes
<repositories>
<repository>
<id>spantus</id>
<name>spantus sourceforge</name>
<url>http://spantus.sourceforge.net/maven/global/</url>
</repository>
</repositories>
and
<dependency>
<groupId>net.sourceforge</groupId>
<artifactId>javaml</artifactId>
<version>0.1.5</version>
</dependency>
My code includes the line
net.sf.javaml.core.Instance instance;
with error
cannot resolve symbol 'net'
(Similarly, imports fail).
Yet mvn package works fine, which indicates it's compiling and finding the dependency. Furthermore the pom.xml shows no error on the dependency.
I've manually navigated the source in version 0.1.5 to make sure the package name for the import is correct. (But mvn compiles it anyway, so no matter).
I have done "invalidate cache and restart" and the error persists."
How can I get intellij to work?
Including this dependency worked for me
<dependency>
<groupId>net.sf</groupId>
<artifactId>javaml</artifactId>
<version>0.1.7</version>
</dependency>
Without setting any repository.
Hope it helps

maven dependecies can't be imported

I have set-up a mave project in Eclipse, I added the project dependencies to the pom.xml which was created by eclipse automatically.
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId> org.springframework.core </artifactId>
<version>3.0.6.RELEASE </version>
</dependency>
</dependencies>
Now when I import the Jdbc template in one of the classes, I get the import can't be resolved error
import org.springframework.jdbc.core.JdbcTemplate;
Are dependencies added during compilation time, or execution time only? if they are only available at execution time, then how can I compile the code?
One way to verify if maven dependencies are added to your project or not in eclipse is under the project ->libraries->Maven Dependencies, all the dependency you have added in your pom.xml should be present
In your case spring-jdbc{version}.jar should there else try to update the project, while updating the project by default all the dependencies would be downloaded to your home directory/.m2/repository. If you find your dependencies are not present check your proxy settings. http://maven.apache.org/guides/mini/guide-proxies.html
The simple problem you have is that the class org.springframework.jdbc.core.JdbcTemplate is contained in the following artifact:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
but not in the spring-core nor as transitive dep. Apart from that you should first check to build the project on command line with Maven and afterward import it into Eclipse.

Maven, package does not exist

I have a module whose pom file is:
<groupId>com.mycompany.Common</groupId>
<artifactId>common</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>common module</name>
In that artifact ('common'), I have a package named com.mycompany.common.objects. In the consuming package, my pom file is:
<dependency>
<groupId>com.mycompany.Common</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
When I run mvn install it always complain: package com.mycompany.common.objects does not exist.
I tried explicit importing in the class where the error was:
import com.mycompany.common.objects
No luck. I tried in both the IDE (IntelliJ) and in commandline. Any idea? thanks
While working with IntellijIDEA, generated files can cause this issue. Writing
mvn idea:idea
on IntellijIDEA Maven console to reset those files did the trick for me. Also, see:
Package doesn't exist error in intelliJ
From your sample, we cannot see any artifact containing the package com.mycompany.common.objects you are using.
You are adding dependency com.mycompany.Common:common as a POM (and you are declaring the packaging of com.mycompany.Common:common as POM too). If it is actually a JAR artifact that contains the package you need to use, then remove the packaging from the POM and dependency (which means, using default which is JAR).
For anyone struggling with this and not familiar with java, make sure that the said package exists in your local repository. Maven has a local repository ~/.m2 where the packages are installed for local access, so even if your dependency package is correctly declared as a dependency in pom.xml and is compiled and exists in your project, if it does not exist in the local repository, the mvn compile will trigger a "package does not exist" error.
To fix this:
In the missing package folder, do:
mvn install //--> this will package and install your missing package in the local repo
Then in your project that you wanted to compile:
mvn compile // --> now that the missing package is in the local repo it should work
Please correct me, If I'm wrong. I understand that the common is a POM that defines several dependencies which intents to be used by other modules. The Importing Dependencies may meet your requirement.
For example
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.mycompany.Common</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I hope this may help.
I had the same problem recently. Everything in my project was setup correctly with dependencies etc. I tried removing /target dirs but nothing worked.
Finally, I solved it by removing the Module Dependency from my dependent project and then readding the dependency. Not sure what is going on in the background, but some sort of refresh of the classpath must have been made. Perhaps the problem was due to the Maven setup.
Hope it helps someone who reaches this question from a search engine.
Not sure if there was file corruption or what, but after confirming proper pom configuration I was able to resolve this issue by deleting the jar from my local m2 repository, forcing Maven to download it again when I ran the tests.
For me the problem was with the sourceDirectory and testSourceDirectory nodes in my pom.xml.
I was using
<sourceDirectory>${basedir}/src/test</sourceDirectory>
<testSourceDirectory>${basedir}/test</testSourceDirectory>
and changed it to
<sourceDirectory>../src/test/java</sourceDirectory>
<testSourceDirectory>../src/test/java</testSourceDirectory>
Your IDE (Eclipse in my case) may not distinguish between compile and runtime scope. This means that the IDE will let you use runtime scope dependencies in your code, but maven won't. In such a such change the dependency scope from runtime to compile.
you need to add the maven-plugin into (each) child module (for compiling main and test source)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugins>
and then you add the plugin-management into the parent pom, for centralizing the plugin config (version...)
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</pluginManagement>
Then you can add your dependency into the dependent module pom
<dependency>
<groupId>com.mycompany.Common</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
http://www.jouvinio.net/wiki/index.php/Projet_Maven_multi-modules

Categories