Specify systemPath to dependency outside pom.xml - java

The problem: My software uses a library that every developer (and user) has installed in a different location.
The following works in pom.xml:
<project ...>
...
<dependencies>
<dependency>
<groupId>myGroup</groupId>
<artifactId>myName</artifactId>
<version>1.2.3</version>
<scope>system</scope>
<systemPath>C:\...\....jar</systemPath>
</dependency>
</dependencies>
</project>
But when I check this into source control, every developer who needs to change it, has to change the pom.xml, thus having to ignore it at every commit afterwards or to commit partially if he has to change anything else in the pom.xml, such as adding another dependency.
Using a property does not help, it just moves the problem to another location inside the pom.xml.
Using a property and reading it from an external file (properties-maven-plugin) seems not to work since the plugin is called after the dependency checks of e.g. Eclipse: Dynamically adding a Maven dependency from a property
Using environment variables ${env.MY_VARIABLE} seems not to work either: [ERROR] 'dependencies.dependency.systemPath' for myGroup:myName:jar must specify an absolute path but is ${env.MY_VARIABLE} #line 123, column 45
Any ideas on how to solve that?

I would use a repoistory for my jars. Something like nexus or artifactory.
https://www.sonatype.com/nexus-repository-sonatype
https://www.jfrog.com/open-source/
https://binary-repositories-comparison.github.io/

this option works for me:
3. Using environment variables ${env.MY_VARIABLE} seems not to work either: [ERROR] 'dependencies.dependency.systemPath' for myGroup:myName:jar must specify an absolute path but is ${env.MY_VARIABLE} #line 123, column 45
you have to put the jar name included in the path, for example, ${env.MY_VARIABLE/my_jar.jar}.
Also make sure that MY_VARIABLE exists in your environment.
at the end execute the mvn clean and mvn compile commands

Related

Difference between ${pom.basedir} vs ${project.basedir} in pom.xml

Getting below warning while build.
I am using in pom.xml
<systemPath>${project.basedir}/lib/....jar</systemPath>
[WARNING] 'dependencies.dependency.systemPath' for ...:jar should not
point at files within the project directory,
${project.basedir}/lib/....jar will be unresolvable by dependent
projects # line 25, column 30
Its resolved now by using <systemPath>${pom.basedir}/lib/....jar in pom.xml
Anyone please explain, What is difference between ${pom.basedir} vs ${project.basedir} in pom.xml?
${basedir}, ${project.basedir} and ${pom.basedir} are synonyms (you may also check that using something like mvn help:evaluate -Dexpression=pom.basedir), your Q just reveals that person who was fixing MNG-4953 didn't know about that.

Cannot resolve org.apache.nifi:nifi-standard-services-api-nar - How to use LookupService inside CustomProcessor

I'm implementing Custom NiFi Processor to decode some files. During the decode process I need to lookup external CSV record for certain data mapping. Note the this decoding process is complex so it has to be a custom processor. I know I can setup external CSVRecordLookupService and then within my CustomController I can define a property descriptor as below
public static final PropertyDescriptor CLIENT_LOOKUP_SERVICE =
new PropertyDescriptor.Builder()
.name("Client CSV Lookup service")
.identifiesControllerService(LookupService.class)
.required(true)
.build();
My first problem is How to refer LookupService.class, which maven Jar package should I use. After bit of investigation I found this https://mvnrepository.com/artifact/org.apache.nifi/nifi-standard-services-api-nar/1.13.0. So I added it to my processors pom.xml as below
<!-- https://mvnrepository.com/artifact/org.apache.nifi/nifi-standard-services-api-nar -->
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>1.13.0</version>
</dependency>
Now I can compile my class and LookupService is visible to the code. However I cannot build the nar or run the maven as it gives Cannot resolve org.apache.nifi:nifi-standard-services-api-nar:1.13.0 error
in the IDEA it also shows the error
How to solve this issue and use org.apache.nifi.lookup.LookupService in my custom processor.
I believe it probably because it comes as nar instead of jar. But my question is how do I use LookupService at compile time only and use the NiFi provided classes at run time by solving this issue.
UPDATE
I'd like to provide an update on this, but the issue is not fully resolved.
I found a jar in maven repo which has the LookupService
This together with org.apache.nifi.serialization.record.Record I can compile and run the maven successfully. 
According to maven repo dependency both these should be declared with the scope provided. So I did that.
Now the problem is I cannot package the nar. It doesn't like the I excluded the LookupService class. even if I remove provided scope it doesn't get included as well.
[INFO] Generating documentation for NiFi extensions in the NAR...
[INFO] Found a dependency on version 1.13.0 of NiFi API
[ERROR] Could not generate extensions' documentation
java.lang.NoClassDefFoundError: org/apache/nifi/lookup/LookupService
...
...
[ERROR] Failed to execute goal org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar (default-nar) on project nifi-decoder-processors-nar: Execution default-nar of goal org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar failed: A required class was missing while executing org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar: org/apache/nifi/lookup/LookupService
[ERROR] -----------------------------------------------------
[ERROR] realm = extension>org.apache.nifi:nifi-nar-maven-plugin:1.3.1
So how do we use this LookupService in our custom processors?
in order to make use of it in runtime you must add below dependency in nifi-decoder-processors-nar's pom file. type is nar
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>1.13.0</version>
<type>nar</type>
</dependency>
as for compiler time add below in nifi-decoder-processors-processors ' pom file (I found it in Nar's pom.xml in repository, you may think NAR as collection of dependency)
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-lookup-service-api</artifactId>
<version>1.13.0</version>
<scope>provided</scope>
</dependency>
see this post

Disabling Maven Dependency?

I'm having a strange problem with my project. There are two dependencies in my POM.xml that belong to my company's repository that I would like to delete and replace them with others that are in my local machine . However, when I do, the maven build fails with the following error:
Error:(21,27) java: unmappable character (0xE9) for encoding UTF-8
All I did was delete the two dependencing from POM and from classpath and replace them with the libraries in my local machine.
Could somebody please tell me why the build fails when I delete them from the POM, as if the encoding was depended on them?! And most importantly, if I can't delete them, is there a way I could keep in the POM all while disabling them?
I tried to edit the libraries themselves by addng:
<scope>system</scope>
<systemPath>Path/to/the/local/library</systemPath>
But Maven didn't like it:
'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-jar-plugin # line 865, column 21
Reporting configuration should be done in <reporting> section, not in maven-site-plugin <configuration> as reportPlugins parameter. #

java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration

I keep getting this error.I've included the hadoop commons and the core libs in the classpath but still i keep getting this error.Help would be highly appreciated
Here's how to troubleshoot: Look inside the jar that you're executing to see if that class file is actually there:
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
If it's not, you need to add it to your classpath or change the way your jar is packaged.
Are you using Maven or some similar build tool? You may have a dependency with a 'scope', which means that it will only be compiled into your jar in certain circumstances.
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
In this example, the scope tag tells Maven that you're using this dependency for building, but it indicates that the dependency will be provided during runtime, so you'll either need to remove this tag or add the hadoop jar using -cp=/path/to/jar.jar during runtime. Another example of a scope like this is 'test', which indicates that the jar is only needed in the path during unit tests.
make sure the classpath in your jar. You can check it like mark said;
jar tvf target/my-jar-with-dependencies.jar | grep hadoop/conf/Configuration.class
add dependency to hadoop-core.

maven dependency version?

I am new to maven. i have a project and it has a pom. inside the pom there is a dependency as below:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>some-project</artifactId>
<version>${originalVersion}</version>
<scope>compile</scope>
</dependency>
My question is where is ${originalVersion} value coming from?
Thanks!
It is either defined somewhere else in the pom, in a parent-pom (there can be several of those, because parents can have parents too), or via a profile (that might be defined somewhere else, like your settings.xml). It could also have been passed as a command-line parameter to maven, but you'd probably have noticed that.
originalVersion is not a standard Maven property so it must appear elsewhere such as in a parent pom, like this:
<properties>
<originalVersion>1.2</originalVersion>
</properties>
See Maven Properties Guide
It comes from a property in your pom.xml.
Something like that:
<properties>
<originalVersion>1.0</originalVersion>
</properties>
Look for a <properties> section in the pom.xml file, there must be a entry like <originalVersion>...</originalVersion>.
Check the properties sub section on the maven tutorial page. It says, following are the possible ways to reference a vairable
env.X: Prefixing a variable with "env." will return the shell's environment variable. For example, ${env.PATH} contains the $path
environment variable (%PATH% in Windows).
project.x: A dot (.) notated path in the POM will contain the corresponding element's value. For example:
1.0 is accessible via
${project.version}.
settings.x: A dot (.) notated path in the settings.xml will contain the corresponding element's value. For example:
false is accessible via
${settings.offline}.
Java System Properties: All properties accessible via java.lang.System.getProperties() are available as POM properties, such
as ${java.home}.
x: Set within a element or an external files, the value may be used as ${someVar}.

Categories

Resources