Maven compile error - Package does not exist - java

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.

Related

How include MapDB in a GWT project

I'm using this Guide for adding MapDb to my project.
i'm trying to make a simple user registration but i don't understand where and how i can put the lib inside my project!
Where include this code
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>VERSION</version>
</dependency>
and this code
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
i'm new with GWT and MapDB and if someone can tell me how put the libraries of MapDB with all steps it's can be very grateful!
After that i manage the data store/retrieve in the server gwt application?
While this is a very old question, I'll reply in case it's still helpful to you.
The XML configuration code you've quoted above should be inserted in a Maven POM file. Maven is a configuration management tool for Java-based projects.
If you aren't using or don't want to start using Maven, you can download the jar from Maven central and add it manually to your project.

Unable to create new maven project using jersey-quickstart-webapp archetype

I am a newbie to jersey and maven. I am trying to create a new maven project based on the jersey-quickstart-webapp archetype, using Eclipse (Luna).
When I go to create the project, I select the "jersey-quickstart-webapp" archetype. Eclipse finds this archetype in the "Maven Central" catalog:
However, when I go to create the project, I get the message:
I don't understand why I am getting this. The archetype exists in the central repository at http://repo1.maven.org/maven2/org/glassfish/jersey/archetypes/jersey-quickstart-webapp/2.14/
and Eclipse can find it when I search for it using the create new project wizard.
I have also tried to create the project from this archetype using the command line:
mvn archetype:generate -DarchetypeGroupId=org.glassfish.jersey.archetypes -DarchetypeArticfactId=jersey-quickstart.webapp -DarchetypeVersion=2.2
When I do this, the project is created; however, when I import it, I get the following error appearing in my POM file:
so it cannot download the dependency:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
When I look in my {homepath}.m2 directory, the contents of the jersey-quickstart-webapp download appear to be there. However, the contents of the {homepath}.m2\repository\org\glassfish\jersey\jersey-bom\2.14 download just shows a .lastUpdated file, with no content. The .lastUpdated file has the contents:
http\://repo.maven.apache.org/maven2/.error=Could not transfer artifact org.glassfish.jersey\:jersey-bom\:pom\:2.14 from/to central (http\://repo.maven.apache.org/maven2)\: Access denied to http\://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.14/jersey-bom-2.14.pom. Error code 403, Forbidden
#default-http\://repo.maven.apache.org/maven2/.lastUpdated=1419265078216
I don't understand why this import is failing. When I open a browser and go to
http://repo.maven.apache.org/maven2/org/glassfish/jersey/jersey-bom/2.14/jersey-bom-2.14.pom
I can view the contents no problem.
I am not sure how to move forward on this and create a new project based on the jersey-quickstart-webapp archetype. I appreciate any suggestions. Thanks for the help.
Add Java.net repo in your app:
<project ...>
<repositories>
<repository>
<id>java.net</id>
<url>https://maven.java.net/content/repositories/public/</url>
</repository>
</repositories>
</project>
Check here:
https://books.sonatype.com/m2eclipse-book/reference/repository-sect-repo-view.html
In principle it's central repository which should be updated.

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>

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, 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