maven dependency java.util.function not properly loading for function class - java

When I build this in maven it compiles successfully.
package com.hf.arm;
import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
public class App
{
public static void main( String[] args )
{
SparkConf conf = new SparkConf().setAppName("FP-growth Example");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
}
}
I need to add a bit of code and so the new script looks like:
package com.hf.arm;
import org.apache.spark.SparkConf;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.mllib.fpm.AssociationRules;
import org.apache.spark.mllib.fpm.FPGrowth;
import org.apache.spark.mllib.fpm.FPGrowthModel;
public class App
{
public static void main( String[] args )
{
SparkConf conf = new SparkConf().setAppName("FP-growth Example");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> data = sc.textFile("/Users/lincolnsmith/Table_csv/sample_fpgrowth.txt");
JavaRDD<List<String>> transactions = data.map(
new Function<String, List<String>>() {
public List<String> call(String line) {
String[] parts = line.split(" ");
return Arrays.asList(parts);
}
}
);
FPGrowth fpg = new FPGrowth()
.setMinSupport(0.2)
.setNumPartitions(10);
FPGrowthModel<String> model = fpg.run(transactions);
for (FPGrowth.FreqItemset<String> itemset: model.freqItemsets().toJavaRDD().collect()) {
System.out.println("[" + itemset.javaItems() + "], " + itemset.freq());
}
double minConfidence = 0.8;
for (AssociationRules.Rule<String> rule
: model.generateAssociationRules(minConfidence).toJavaRDD().collect()) {
System.out.println(
rule.javaAntecedent() + " => " + rule.javaConsequent() + ", " + rule.confidence());
}
}
}
But I get this error:
"cannot find symbol symbol: class Function"
Obviously I'm missing the package java.utils.function and so I import this
import java.util.function.Function;
And I add the dependency to my pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hf.arm</groupId>
<artifactId>arm</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>arm</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.10</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>net.sf.m-m-m</groupId>
<artifactId>mmm-util-backport-java.util.function</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
But now I continue to get the error output:
Lincolns-MacBook-Pro:arm lincolnsmith$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building arm 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # arm ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/lincolnsmith/Table_csv/arm/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # arm ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /Users/lincolnsmith/Table_csv/arm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.241 s
[INFO] Finished at: 2015-10-14T10:05:13-04:00
[INFO] Final Memory: 19M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project arm: Compilation failure: Compilation failure:
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,11] '.' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,12] ';' expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,16] class, interface, or enum expected
[ERROR] /Users/lincolnsmith/Table_csv/arm/src/main/java/com/hf/arm/App.java:[6,17] class, interface, or enum expected
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I can't find a different maven source for this dependency and I've tried cleaning and emptying my.m2 directory. Is there a different dependency source for java.utils.function that I can use for maven or is something else wrong?
Here is my java version:
Lincolns-MacBook-Pro:arm lincolnsmith$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

Actually you don't need backport package as Function belong to Spark API, not to Java 8 API. Try this instead:
JavaRDD<List<String>> transactions = data.map(
new org.apache.spark.api.java.function.Function<String, List<String>>() {
public List<String> call(String line) throws Exception {
String[] parts = line.split(" ");
return Arrays.asList(parts);
}
}
);
Then you can build and run your application with correct classpath:
mvn clean compile exec:java -Dexec.mainClass="com.hf.App"
And it works pretty fine (with expected result in my case):
...
org.apache.spark.SparkException: A master URL must be set in your configuration
at org.apache.spark.SparkContext.<init>(SparkContext.scala:394)
...

Related

Java8 maven raise Error reference to filter is ambiguous

I'm running a Spark quick start application:
/* SimpleApp.java */
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.Dataset;
public class SimpleApp {
public static void main(String[] args) {
String logFile = "/data/software/spark-2.4.4-bin-without-hadoop/README.md"; // Should be some file on your system
SparkSession spark = SparkSession.builder().appName("Simple Application").getOrCreate();
Dataset<String> logData = spark.read().textFile(logFile).cache();
long numAs = logData.filter(s -> s.contains("a")).count();
long numBs = logData.filter(s -> s.contains("b")).count();
System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);
spark.stop();
}
}
As the official document told,
# Package a JAR containing your application
$ mvn package
When I ran mvn package it raise the below error:
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/dennis/java/spark_quick_start/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/dennis/java/spark_quick_start/src/main/java/SimpleApp.java:[11,25] reference to filter is ambiguous
both method filter(scala.Function1<T,java.lang.Object>) in org.apache.spark.sql.Dataset and method filter(org.apache.spark.api.java.function.FilterFunction<T>) in org.apache.spark.sql.Dataset match
[ERROR] /home/dennis/java/spark_quick_start/src/main/java/SimpleApp.java:[12,25] reference to filter is ambiguous
both method filter(scala.Function1<T,java.lang.Object>) in org.apache.spark.sql.Dataset and method filter(org.apache.spark.api.java.function.FilterFunction<T>) in org.apache.spark.sql.Dataset match
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:00 min
[INFO] Finished at: 2020-01-13T15:04:55+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project simple-project: Compilation failure: Compilation failure:
[ERROR] /home/dennis/java/spark_quick_start/src/main/java/SimpleApp.java:[11,25] reference to filter is ambiguous
[ERROR] both method filter(scala.Function1<T,java.lang.Object>) in org.apache.spark.sql.Dataset and method filter(org.apache.spark.api.java.function.FilterFunction<T>) in org.apache.spark.sql.Dataset match
[ERROR] /home/dennis/java/spark_quick_start/src/main/java/SimpleApp.java:[12,25] reference to filter is ambiguous
[ERROR] both method filter(scala.Function1<T,java.lang.Object>) in org.apache.spark.sql.Dataset and method filter(org.apache.spark.api.java.function.FilterFunction<T>) in org.apache.spark.sql.Dataset match
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
This is pom.xml:
<project>
<groupId>edu.berkeley</groupId>
<artifactId>simple-project</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>Simple Project</name>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.12</artifactId>
<version>2.4.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
It means that your lambda expression can both be turned into a scala.Function1<T,java.lang.Object>or a org.apache.spark.api.java.function.FilterFunction<T>.
I don't know if this would be ambiguous in Scala as well, but in Java it is. You need to explicitely state the type in this case:
long numAs = logData.filter((org.apache.spark.api.java.function.FilterFunction<String>)s -> s.contains("a")).count();
Or write the code in Scala.
It seems to be an compatible issue, as Spark 2.4.4 is using Scala 2.11 (I'm not sure). Because I saw this from the official website:
After changing to 2.11, all is working fine!
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.4.4</version>
<scope>provided</scope>
</dependency>
You can convert lambda expression to anonymous class creation as shown in below example:
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.SparkSession;
import scala.Function1;
public class SimpleApp {
public static void main(String[] args) {
String logFile = "/data/software/spark-2.4.4-bin-without-hadoop/README.md"; // Should be some file on your system
SparkSession spark = SparkSession.builder().appName("Simple Application").getOrCreate();
Dataset<String> logData = spark.read().textFile(logFile).cache();
long numAs = logData.filter(new Function1<String, Object>() {
public Object apply(String s) {
return s.contains("a");
}
}).count();
long numBs = logData.filter(new Function1<String, Object>() {
public Object apply(String s) {
return s.contains("b");
}
}).count();
System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);
spark.stop();
}
}

How to fix "The import org.apache.poi cannot be resolved"

I want to make use of Apache-POI in my code, but am getting an error message The import org.apache.poi cannot be resolved at the import statement
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
I am a beginner with a freshly set up Visual Studio Code v1.30.2, Maven 3.6.0, Java JRE 1.8.0_201.
I have activated the following extensions:
Debugger for Java, 0.16.0
Java dependency viewer, 0.3.0
Java extension pack, 0.5.0
Java test runner, 0.14.0
Language support for Java (TM), 0.37.0
Maven for Java, 0.14.0
I entered these statements in the pom.xml in the dependency section:
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
I've also tried with other POI versions, e.g. 3.10-FINAL.
I'm too new to Java, Maven and VSCode to be sure I've included all the necessary information to point to a solution. Please help me :)
I've run mvn compile, with this result:
C:\Users\MYUSERNAME\Documents\Java\project2>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< MYNAME.project2:project2 >---------------------
[INFO] Building project2 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # project2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\MYUSERNAME\Documents\Java\project2\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # project2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\MYUSERNAME\Documents\Java\project2\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[12,1] package org.apache.poi.ss.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[13,37] package org.apache.poi.xssf.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[14,37] package org.apache.poi.xssf.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[46,9] cannot find symbol
symbol: class XSSFWorkbook
location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[46,45] cannot find symbol
symbol: class XSSFWorkbook
location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[48,9] cannot find symbol
symbol: class XSSFSheet
location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[55,13] cannot find symbol
symbol: method setCellValue(java.lang.String)
location: variable cell of type com.google.common.collect.Table.Cell
[INFO] 7 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.549 s
[INFO] Finished at: 2019-01-30T09:41:45+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project project2: Compilation failure: Compilation failure:
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[12,1] package org.apache.poi.ss.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[13,37] package org.apache.poi.xssf.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[14,37] package org.apache.poi.xssf.usermodel does not exist
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[46,9] cannot find symbol
[ERROR] symbol: class XSSFWorkbook
[ERROR] location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[46,45] cannot find symbol
[ERROR] symbol: class XSSFWorkbook
[ERROR] location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[48,9] cannot find symbol
[ERROR] symbol: class XSSFSheet
[ERROR] location: class MYNAME.project2.App
[ERROR] /C:/Users/MYUSERNAME/Documents/Java/project2/src/main/java/MYNAME/project2/App.java:[55,13] cannot find symbol
[ERROR] symbol: method setCellValue(java.lang.String)
[ERROR] location: variable cell of type com.google.common.collect.Table.Cell
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/
I've also pasted the full output of mvn -X compile here
I've pasted my full POM.XML here
In my local folder C:\Users\MYUSERNAME.m2\repository\org\apache there is no subfolder poi.
Thanks all contributors, and especially to #ayZagen (who pointed me towards the pom.xml).
It turns out that I had inserted the dependencies for poi into the dependencies section of
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
rather than into the correct section <project> <dependencies>.
When I moved my dependencies to the correct section, maven downloads POI and that part of the code compiles.
Sorry for taking people's time over a trivial error. Thank you for helping me to find out, and asking the right questions! This was a very positive experience!
As per the error log there are 2 possibilities
Network issue.
Maven is not able to download the jar files from its repository, so there is no POI library at .m2 folder
Solution: Check the network/ Internet.
Files corrupted. This happens if file(s) got corrupted.
Solution: delete the folder org.apache.poi inside .m2 folder. the Right click on project(from Eclipse) --> Maven --> Update project. Then clean & refresh project, then Run command Maven clean install
EDIT
Try moving poi dependencies to the root dependencies tag.
Run mvn compile
The first time you execute this (or any other) command, Maven will
need to download all the plugins and related dependencies it needs to
fulfill the command. From a clean installation of Maven, this can take
quite a while (in the output above, it took almost 4 minutes). If you
execute the command again, Maven will now have what it needs, so it
won't need to download anything new and will be able to execute the
command much more quickly.
Maven: Getting Started

maven error: cannot find symbol class in a package

This is my first time using maven and i'm trying to understand how it works. Therefore i have a small example with two classes in different packages.
package maven.callee ;
public class Callee {
public void callMe() {
System.out.println("Callee says: You called me!");
}
}
And now the Caller class with the main function.
package maven.caller ;
import maven.callee.Callee ;
public class Caller {
public static void main(String [] args) {
Callee callee = new Callee ();
callee.callMe ();
}
}
I know the structure of the src directory is not the same as the standard.
When i run the command mvn package on the pom.xml file i get the following output:
[INFO] Compiling 1 source file to /home/ced/workspaceForOxygene/build/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
symbol: class Callee
location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
symbol: class Callee
location: class maven.caller.Caller
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.645 s
[INFO] Finished at: 2018-04-24T17:12:36+02:00
[INFO] Final Memory: 13M/158M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project mavenTest: Compilation failure: Compilation failure:
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[2,20] package maven.callee does not exist
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,4] cannot find symbol
[ERROR] symbol: class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] /home/ced/workspaceForOxygene/build/src/maven/caller/Caller.java:[6,24] cannot find symbol
[ERROR] symbol: class Callee
[ERROR] location: class maven.caller.Caller
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Please what happening hier? why can't maven locate that file? hier is my POM file, what i am doing wrong?
<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>com.swt.build</groupId>
<artifactId>mavenTest</artifactId>
<version>1.0</version>
<build>
<sourceDirectory>src/maven/caller</sourceDirectory>
<!--specify output directory for binaries -->
<outputDirectory> classes </outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins </groupId>
<artifactId> maven-jar-plugin</artifactId>
<version> 3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath> true </addClasspath>
<mainClass> maven.caller.Caller </mainClass>
</manifest>
</archive>
<!--specify output directory for jar file -->
<outputDirectory>jars</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
maven.callee is missing from compiler path. It should be part of source dir or should be defined as lib dependency. With the current setting, Maven will try to compile the java files only under src/maven/caller.
Change sourceDirectory to src/maven in pom.xml.

Neo4J Browser does not show any results on connecting with Java API

I'm trying to connect to Neo4J using Java, and have been following this sample demo.
I setup a new Maven Project, and added the code which creates a few Nodes and Relationships among the nodes. This is how my main class looks like -
package neo4j;
import org.neo4j.cypher.internal.compiler.v2_3.No;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import java.io.File;
/**
* Created by manish on 5/15/17.
*/
public class Neo4JDemo {
public enum NodeType implements Label {
Person, Course, Dummy;
}
public enum RelationType implements RelationshipType {
Knows, BelongsTo;
}
public static void main(String[] args) {
GraphDatabaseFactory databaseFactory = new GraphDatabaseFactory();
File file = new File("/home/manish/Documents/Development/Software/neo4j-community-3.1.4/data/databases/graph.db");
GraphDatabaseService graphDatabaseService = databaseFactory.newEmbeddedDatabase(file);
try(Transaction tx = graphDatabaseService.beginTx()) {
Node bobNode = graphDatabaseService.createNode(NodeType.Person);
bobNode.setProperty("PID", 5001);
bobNode.setProperty("Name", "Bob");
bobNode.setProperty("Age", 23);
Node bNode = graphDatabaseService.createNode(NodeType.Dummy);
bNode.setProperty("PID", 5001);
bNode.setProperty("Name", "Bob");
bNode.setProperty("Age", 23);
Node aliceNode = graphDatabaseService.createNode(NodeType.Person);
aliceNode.setProperty("PID", 5002);
aliceNode.setProperty("Name", "Alice");
aliceNode.setProperty("Age", 20);
Node eveNode = graphDatabaseService.createNode(NodeType.Person);
eveNode.setProperty("PID", 5003);
eveNode.setProperty("Name", "Eve");
eveNode.setProperty("Age", 25);
Node itNode = graphDatabaseService.createNode(NodeType.Course);
itNode.setProperty("ID", 1);
itNode.setProperty("Name", "IT Beginners");
itNode.setProperty("Location", "Room 154");
Node ecNode = graphDatabaseService.createNode(NodeType.Course);
ecNode.setProperty("ID", 2);
ecNode.setProperty("Name", "Advanced Electronics");
bobNode.createRelationshipTo(aliceNode, RelationType.Knows);
Relationship bobRelIt = bobNode.createRelationshipTo(itNode, RelationType.BelongsTo);
bobRelIt.setProperty("Role", "Student");
Relationship bobRelEc = bobNode.createRelationshipTo(ecNode, RelationType.BelongsTo);
bobRelEc.setProperty("Role", "Supply Teacher");
Relationship aliceRelIt = aliceNode.createRelationshipTo(itNode, RelationType.BelongsTo);
aliceRelIt.setProperty("Role", "Teacher");
tx.success();
}
graphDatabaseService.shutdown();
}
}
When I run the project, it compiles successfully -
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for neo4j:neo4j-setup:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # line 10, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building neo4j-setup 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # neo4j-setup ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/manish/Documents/Development/Thesis/Neo4J-Test1/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # neo4j-setup ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/manish/Documents/Development/Thesis/Neo4J-Test1/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.420 s
[INFO] Finished at: 2017-05-15T19:24:46-04:00
[INFO] Final Memory: 25M/263M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
However, when I head over to the Neo4J Browser at localhost:7474, there are no nodes or relationships of the type that was created through this Java code -
I'm not sure what's going wrong, and would appreciate any help with this.
UPDATE - including pom.xml -
<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>neo4j</groupId>
<artifactId>neo4j-setup</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<name>neo4j-setup</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.4</version>
</dependency>
</dependencies>
</project>

mvn COMPILATION ERROR : error reading jar error in opening zip file

i have a x-module with those properties:
module-name: x-datamodel
this is a part of the pom.xml
<groupId>com.x.datamodel</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
i have install the project in a local repository with this command line:
mvn install:install-file -Dfile=/Users/me/Documents/Projects/x-datamodel/target/classes/x-datamodel.jar -DgroupId=com.x.datamodel -DgeneratePom=true -DlocalRepositoryPath=/Users/me/Documents/Projects/me-repository -DcreateChecksum=true -DartifactId=x -Dversion={1.0} -Dpackaging=jar
and added the project in bitbucket.
I try to integrate the module x in another project y.
here a part of the y's pom.xml
<dependency>
<groupId>com.x.datamodel</groupId>
<artifactId>x</artifactId>
<version>${x.version}</version>
</dependency>
<repositories>
<repository>
<id>me-repository</id>
<url>https://bitbucket.org/me/me-repository/src/master</url>
</repository>
</repositories>
i can import some classes of the module x in the project y, but when i build the y project i get this error:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[3,32] package com.x.datamodel.model does not exist
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[18,12] cannot find symbol
symbol: class User
location: class com.y.server.serviceImpl.UserServiceImpl
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/security/CustomUserDetailsService.java:[3,32] package com.x.datamodel.model does not exist
[INFO] 16 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:56 min
[INFO] Finished at: 2016-12-28T15:51:05+01:00
[INFO] Final Memory: 29M/209M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project y: Compilation failure: Compilation failure:
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] error reading /Users/me/.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar; error in opening zip file
[ERROR] /Users/me/Documents/Projects/y/src/main/java/com/y/server/serviceImpl/UserServiceImpl.java:[3,32] package com.x.datamodel.model does not exist
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
after installing the repository i have the library into this path:
.m2/repository/com/x/datamodel/x/1.0/x-1.0.jar
why not:
.m2/repository/com/x-datamodel/x/1.0/x-1.0.jar
I tend to think the file is corrupted. Try deleting it and downloading it again.
Try removing the below lines
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
With :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>

Categories