intellij not finding maven imports from third party repository - java

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

Related

Missing package for org.apache.http, JAR can't be found

I need the org.apache.http package, where i have tried to use the find JAR on web function built inside intelliJ, but no matter, what jar i try to get, it all returns 404 (is this because the package is depricated?)
how is the error i get when i try:
Is there any way to get this jar package?
Try downloading it from maven repositories
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.4.12
If it's a maven project, specify in your pom.xml the repository. And add the dependencies to apache.
<repositories>
<repository>
<id>my-repo</id>
<url>https://my repo.com</url>
</repository>
</repositories>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.12</version>
</dependency>

Maven compile error - Package does not exist

I'm starting a microservices project, based on the MVC architecture, where the MODEL part of it will be used by all of the microservices. For that I've created a project (HabilWeb_Commons) with the Model part of the webapp and with some classes that will be common for all of the other microservices.
The problem happens when I try to add the HabilWeb_Commons project to another, using Maven.
Below is a snippet of my pom.xml file:
<repositories>
<repository>
<id>internal-repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>HabilWeb_Commons</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependencies>
In every reference to any of the classes from the HabilWeb_Commons project, when I try to build the microservice, the following errors happen:
br/com/koinonia/habil/controller/EmpresaController.java:[8,35] package br.com.koinonia.habil.model does not exist
br/com/koinonia/habil/controller/EmpresaController.java:[19,59] cannot find symbol
symbol: class Empresa
Class Empresa is created in HabilWeb_Commons project, in the following package path: br.com.koinonia.habil.model
I Have absolutely no idea what I'm doing wrong, since I already tried this approach with other projects with no problem.
Can anyone help?
I solved this problem creating a maven based project, with multiple modules, HabilWeb_Commons being one of this modules. Works like a charm.

Unable To Use ch.qos.logback.classic Classes

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>

JAHMM Package Maven

I need to work with be.ac.ulg.montefiore.run.jahmm package for Hidden Markov Models in java.
My project is a mevenized project so I need to use the corresponding dependency.
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
The above dependency is not being resolved in my project.
Does anyone know how to help me?
Thank you.
Your dependency is not in the Maven Central Repository.
Find out the repository used by the authors to publish their artifacts and add this repository to your POM or to your settings.xml.
If it is not published to the usual online maven repositories, you will need to install it on your local machine first.
So download the sources, go to the top level and do the usual
mvn install
Once you installed jahmm locally, your project can resolve it from your maven cache.
Adding this repository should do the trick:
<repositories>
<repository>
<id>jsi</id>
<url>http://repo.springsource.org/libs-release-remote</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>be.ac.ulg.montefiore.run.jahmm</groupId>
<artifactId>jahmm</artifactId>
<version>0.6.2</version>
</dependency>
...
</dependencies>

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