during maven build [mvn install] dependencies not getting downloaded from repository - java

I am new to pom but went through the "Getting started" on maven.apache.org and also referred to an existing project within the company before i started on this project.
Info:
If i specify the jars as referenced libs in eclipse the project is running smooth and no issues are observed.
Problem: compilation errors since unable to download dependent code from repository.
My project structure is [simplified for easier understanding]
utils
utils/commons [has source in src/main/java style] [uses package org.apache.commons.io.IOUtils]
utils/commons/pom.xml
utils/pom.xml [parent]
Now I began with commons folder to write the pom.xml as the only module and no reference to any parent / other module.
After I ran mvn install it gave errors as
ToolUtils.java:[17,28] error: package org.apache.commons.io does not exist
ToolUtils.java:[18,23] error: package org.apache.log4j does not exist
If i commented the code which was using org.apache.commons.io.IOUtils then the mvn install works fine and generates a jar.
I looked up the net and found that the issue is failing to locate the repository so i updated the reference
to parent pom.xml.
And also included the repositories details in the parent pom.xml. [which is directly under utils folder]
I am still getting the same error and the build does not move further.
ToolUtils.java:[17,28] error: package org.apache.commons.io does not exist
ToolUtils.java:[18,23] error: package org.apache.log4j does not exist
I am using an internal URL which i have verified manually in a broswer.
Also I have verified that the proxy details are correct since another old project refers to the same URL and is getting built properly.
[Unfortunately the project is far too complex to copy paste the pom.xml and modify ,
hence writing the pom.xml from scratch.]
Can some point what am i missing which causes no download from repository ?
Thanks in advance.
Any help would be deeply appreciated.
Note:
1) I am pasting snippets from the 2 different pom.xml with their directory names for easier identification. Attachments can be provided on request.
2) I have modified the references to confidential data across to protect some identities.
utils/common/pom.xml [commons module]
....
<parent>
<groupId>com.osg.rtos</groupId>
<artifactId>rxutils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
....
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-commons-service</artifactId>
<version>${rtos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
utils/pom.xml [parent]
....
<groupId>com.osg.rtos</groupId>
<artifactId>rxutils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rxutils</name>
<packaging>pom</packaging>
<repositories>
<repository>
<id>release</id>
<url>http://internal.com/~devbuild/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-commons-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-data</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-exception</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-mailbox-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-message-service</artifactId>
<version>${rtos.version}</version>
</dependency>
<dependency>
<groupId>com.osg.rtos</groupId>
<artifactId>rtos-rest</artifactId>
<version>${rtos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>commons</module>
<module>rxutils</module>
<module>tool</module>
</modules>
...

You need to remove the <dependencyManagement> tags that surround the <dependencies> section in the commons module pom.xml.
The <dependencyManagement> section allows you to specify dependency information, such as version number, in a parent pom (as you have done) so that you can simplify dependencies in the child poms. However, you still need a <dependencies> section to specify what dependencies are required for that child.

in pom.xml use
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
remove or comment <exclusions> and <exclusion>

Related

Maven doesn't compile the project with jNativeHook from Github

I have added Jitpack repo and dependency from Github to pom.xml and it still doesn't compile. However, when I point onto the line in import block, it clearly shows the description of a module.
VSCode screenshot
For example, I try to import com.github.kwhat.jnativehook.GlobalScreen, it shows the description of the module but still underlines the line with red and shows the error:
The type com.github.kwhat.jnativehook.GlobalScreen is not accessible Java(16778666)
What could be the problem?
Here's a part of pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>com.github.kwhat</groupId>
<artifactId>jnativehook</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
Just try to synchronize you project.
I add an imagine where can be seen that dependencies is load correctly..

Spring and Hibernate dependencies are not being resolved

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.

Package doesnot exist on maven compilation

There exist a class in project that uses ILoggingEvent which is found to be imported from logback-classic.jar. It is available in project as maven dependency as well and in .m2 folder. But when i do mvn clean install, I get below error:
[ERROR] /C:/Users/xxx/project/LogMonitor.java:[6,34] package
ch.qos.logback.classic.spi does not exist
cannot find symbol symbol:
class ILoggingEvent
When i extracted files from jar,I was able to find the same package with that jar. Above all , i see no error mark in LogMonitor class too , though it is the one which uses ILoggingEvent
I tried maven update,project clean. But still i see it failing. There is no issue in configuration of maven as another repository is built successful. Please favour on how it can be resolved
Edit:
pom file of repo where this code exist.:
<parent>
<groupId>com.common</groupId>
<artifactId>common-pom</artifactId>
<version>0.25.5</version>
</parent>
<artifactId>aws</artifactId>
pom of common:
<groupId>com.common</groupId>
<artifactId>common-pom</artifactId>
<version>0.25.5</version>
<packaging>pom</packaging>
<name>Common</name>
<modules>
<module>xxx</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>xxx</artifactId>
<version>${project.version}</version>
</dependency>
<dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
</dependencies>
First of all it is bad practice to have actual dependencies in a parent pom. Instead you should only have the dependency-management in the parent pom to specify the versions of the dependencies that should be used and then in the consuming children the required dependencies. Otherwise you might end-up with jars on the classpaths of projects that do not actually require them.
In short:
The parent pom (you common pom) should only contain:
<groupId>com.common</groupId>
<artifactId>common-pom</artifactId>
<version>0.25.5</version>
<packaging>pom</packaging>
<name>Common</name>
<modules>
<module>xxx</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
<dependencies>
<dependencyManagement>
And the consumers of the parent pom will then contain the dependencies without the version number:
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
The important part is that you specify the correct version number and the designated scope at some point(see https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope).
Your dependency should look like this:
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
The scope is maybe set to <scope>test</scope> . If you want to use it in src/main/java, you have to set the scope at compile (default when no scope is defined)

NIFI: No controller service types found that are applicable for this property

I am developing a Milo OPCUA Processor and Service for Apache NiFi.
The Processor and Service compile fine, and I am able to start NiFi with them. However, when trying to configure the service for the processor that I just added, it just says "No controller service types found that are applicable for this property.".
Here are my POMs:
Processor JAR
<parent>
<groupId>com.tcon</groupId>
<artifactId>pubsub</artifactId>
<version>0.1</version>
</parent>
<artifactId>nifi-pubsub-processors</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>tcon</groupId>
<artifactId>nifi-miloservice-api</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
Processor NAR
<parent>
<groupId>com.tcon</groupId>
<artifactId>pubsub</artifactId>
<version>0.1</version>
</parent>
<artifactId>nifi-pubsub-nar</artifactId>
<version>0.1</version>
<packaging>nar</packaging>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>com.tcon</groupId>
<artifactId>nifi-pubsub-processors</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>1.2.0</version>
<type>nar</type>
</dependency>
</dependencies>
The service POMs shouldn't matter, afaik. They haven't been modified, save for a few Milo dependencies.
As you can see, the processor JAR POM has the custom service API dependency from my custom service and the processor NAR POM has the standard API dependency from nifi.
The docs say that that is all I need to do to "link" my processor to my service.
What am I missing?
You also need to register your controller service with the ServiceLoader by including a file in the src/main/resources folder of your processor JAR project. You'll need a META-INF/services folder under your resources folder, with a file called org.apache.nifi.controller.ControllerService with a line containing the fully qualified name of the class implementing the ControllerService interface.

Missing artifact net.sf.jung:jung2:jar:2.0

jung2 is in maven repository, here and here.
But my Eclipse does not finding it out:
Code is here:
<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>tests.jung</groupId>
<artifactId>TryJung</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung2</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>
UPDATE
Sorry can't accept answers about dependency type, because it is not complete. The code for jung dependency was taken from Maven repository directly:
So, I need an explanation, why doesn't code, taken from repository site, work actually.
What is happening here, who is "guilty"?
As already said, you are addressing a pom file. Which is, in a sense, correct, but if you want to compile you will need to add the actual jars in the dependencies section, such as:
<dependencies>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung2</artifactId>
<version>${jung.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-api</artifactId>
<version>${jung.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-visualization</artifactId>
<version>${jung.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-graph-impl</artifactId>
<version>${jung.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-algorithms</artifactId>
<version>${jung.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.sf.jung</groupId>
<artifactId>jung-io</artifactId>
<version>${jung.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
Do not forget to define the version property also in the properties section:
<properties>
<jung.version>2.0.1</jung.version>
</properties>
Hope this helps.
The problem is simply the artifact you are adressing is a pom file and not a jar file. That's the reason for the message.
just stumbled into the same problem pit. apparently these are pom files purely for building/documenting (all) sub-projects (or submodules in maven speak) of a project (in this case jung2)
they can't be used as a dependency in a useful way
actually you can depend on them with <type>pom</type> but will just include the dependencies of that pom but not it's modules.
see here for a more complete explanation:
How to use POMs as a dependency in Maven?

Categories

Resources