Package doesnot exist on maven compilation - java

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)

Related

How can I get a dependencyNode's premanagedVersion in Maven 3.0+ API?

I have a pom-packaging project called "testMultiManage". The following content is in its pom.xml:
...
<modules>
<module>sub1</module>
<module>sub1/subsub1</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupC</groupId>
<artifactId>C</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</dependencyManagement>
...
In its sub project "sub1", the content in the pom.xml is
<dependencies>
<dependency>
<groupId>groupB</groupId>
<artifactId>B</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
And what in B-1.0.pom is
<dependencies>
<dependency>
<groupId>groupC</groupId>
<artifactId>C</artifactId>
<version>1.0</version>
</dependency>
...
<dependencies>
So, according to maven's management control rules, "sub1" will depend on B-1.0, and then transitively depend on C-2.0.
When I use the following code to get the DependencyGraph with Maven 3.0+ API
DefaultProjectBuildingRequest defaultProjectBuildingRequest = new DefaultProjectBuildingRequest();
defaultProjectBuildingRequest.setRepositorySession(getVerboseRepositorySession(project));
defaultProjectBuildingRequest.setProject(project);
defaultProjectBuildingRequest.setRemoteRepositories(remoteRepositories);
defaultProjectBuildingRequest.setResolveDependencies(true);
org.apache.maven.shared.dependency.graph.DependencyNode dependencyNode = dependencyGraphBuilder.buildDependencyGraph(defaultProjectBuildingRequest, null);
, I get the dependency relationships correctly for project "sub1". However, the premanagedVersion of "C-2.0" is null.
So how can I use Maven 3.0+ API to get a dependency node's premanagedVersion? Thanks a lot!

DependcyManagement or dependencies ?? in pom maven

According to the maven docs Dependency management
is a mechanism for centralizing dependency information.
and from this question here SO Question, many people suggested to use Dependency managmement instead of dependencies when we have a common jar file for all children.
as in dependency management , dependencies are propogated only when children request for it but incase of dependencies the dependecies are propogated even when not required.
but wouldn't it be a better approch when the jar file is common to all children ,i.e when all the children inherit the same jar file
for example (rewritten example taken from maven docs)
child a
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
</dependency>
<dependency>
<groupId>group-c</groupId>
<artifactId>artifact-b</artifactId>
</dependency>
</dependencies>
child b
<dependencies>
<dependency>
<groupId>group-c</groupId>
<artifactId>artifact-b</artifactId>
</dependency>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
</dependency>
</dependencies>
parent of both a and b
<dependencyManagement>
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
but wouldn't this yeild the same result ??
parent of both a and b
<dependencies>
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-a</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
child a
<dependencies>
<dependency>
<groupId>group-c</groupId>
<artifactId>artifact-b</artifactId>
</dependency>
</dependencies>
child b
<dependencies>
<dependency>
<groupId>group-c</groupId>
<artifactId>artifact-b</artifactId>
</dependency>
</dependencies>
or did i misunderstand them??
and which one should i use and in what conditions ??
Dependency management section in the parent pom is managing versions and only versions of these libraries, when you are using them in the child projects.
Dependency section on the contrary ENFORCES all child modules to have these dependencies, regardless child modules need them or not.
If you are sure ALL your child modules will use group-a:module-a:version, then feel free to declare it in parent dependencies section.
If you have at least one child module in the project, where such enforced dependency is unnecessary, then dependencyManagement better suites your need.

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?

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

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>

Categories

Resources