Here is the tutorial I'm following.
The pom.xml file is the default one that comes with the dl4j examples folder so there shouldn't be issues there but it still has errors.
Here's the code:
package org.deeplearning4j.self;
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.learning.config.Adam;
import org.nd4j.linalg.lossfunctions.LossFunctions;
import java.io.IOException;
public class first {
int batchSize = 128; // how many examples to simultaneously train in the network
EmnistDataSetIterator.Set emnistSet = EmnistDataSetIterator.Set.BALANCED;
EmnistDataSetIterator emnistTrain;
{ try { emnistTrain = new EmnistDataSetIterator(emnistSet, batchSize, true); } catch (IOException e) { e.printStackTrace(); } }
EmnistDataSetIterator emnistTest;
{ try { emnistTest = new EmnistDataSetIterator(emnistSet, batchSize, false); } catch (IOException e) { e.printStackTrace(); } }
int outputNum = EmnistDataSetIterator.numLabels(emnistSet);// total output classes
int rngSeed = 123; // integer for reproducability of a random number generator
int numRows = 28; // number of "pixel rows" in an mnist digit
int numColumns = 28;
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.seed(rngSeed)
.updater(new Adam())
.l2(1e-4)
.list()
.layer(new DenseLayer.Builder()
.nIn(numRows * numColumns) // Number of input datapoints.
.nOut(1000) // Number of output datapoints.
.activation(Activation.RELU) // Activation function.
.weightInit(WeightInit.XAVIER) // Weight initialization.
.build())
.layer(new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
.nIn(1000)
.nOut(outputNum)
.activation(Activation.SOFTMAX)
.weightInit(WeightInit.XAVIER)
.build())
.build();
MultiLayerNetwork network = new MultiLayerNetwork(conf);
network.init();
// pass a training listener that reports score every 10 iterations
int eachIterations = 10;
network.addListeners(new ScoreIterationListener(eachIterations));
}
I'm using IntelliJ.
The errors I'm getting in the class is:
Both methods called on "network" aren't recognized, both "init()" and "addListeners()" have "Cannot resolve symbol" on them. It also says on "network" that the "Field network is never used".
Additionally the int "eachIterations" has an "Unknown class" error inside of the addListeners() method.
Here's the pom.xml file:
<?xml version="1.0" encoding="UTF-8"?> <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Copyright (c) 2020 Konduit K.K. ~ Copyright (c) 2015-2019 Skymind, Inc. ~ ~ This program and the accompanying materials are made available under the ~ terms of the Apache License, Version 2.0 which is available at ~ https://www.apache.org/licenses/LICENSE-2.0. ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the ~ License for the specific language governing permissions and limitations ~ under the License. ~ ~ SPDX-License-Identifier: Apache-2.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<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>org.deeplearning4j</groupId>
<artifactId>dl4j-examples</artifactId>
<version>1.0.0-beta7</version>
<name>Introduction to DL4J</name>
<description>A set of examples introducing the DL4J framework</description>
<properties>
<dl4j-master.version>1.0.0-beta7</dl4j-master.version>
<!-- Change the nd4j.backend property to nd4j-cuda-X-platform to use CUDA GPUs -->
<!-- <nd4j.backend>nd4j-cuda-10.2-platform</nd4j.backend> -->
<nd4j.backend>nd4j-native</nd4j.backend>
<java.version>1.8</java.version>
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
<maven.minimum.version>3.3.1</maven.minimum.version>
<exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
<maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
<jcommon.version>1.0.23</jcommon.version>
<jfreechart.version>1.0.13</jfreechart.version>
<logback.version>1.1.7</logback.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.29</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>4.1.48.Final</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>${nd4j.backend}</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-data-image</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-local</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-datasets</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-ui</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-zoo</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<!-- ParallelWrapper & ParallelInference live here -->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-parallel-wrapper</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<!-- Used in the feedforward/classification/MLP* and feedforward/regression/RegressionMathFunctions example -->
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>${jfreechart.version}</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>${jcommon.version}</version>
</dependency>
<!-- Used for downloading data in some of the examples -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-data-codec</artifactId>
<version>${dl4j-master.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
<!-- Maven Enforcer: Ensures user has an up to date version of Maven before building -->
<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-default</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[${maven.minimum.version},)</version>
<message>********** Minimum Maven Version is ${maven.minimum.version}. Please upgrade Maven before continuing (run "mvn --version" to check). **********</message>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>com.lewisd</groupId>
<artifactId>lint-maven-plugin</artifactId>
<version>0.0.11</version>
<configuration>
<failOnViolation>true</failOnViolation>
<onlyRunRules>
<rule>DuplicateDep</rule>
<rule>RedundantPluginVersion</rule>
<!-- Rules incompatible with Java 9
<rule>VersionProp</rule>
<rule>DotVersionProperty</rule> -->
</onlyRunRules>
</configuration>
<executions>
<execution>
<id>pom-lint</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>${shadedClassifier}</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>org/datanucleus/**</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.lewisd</groupId>
<artifactId>lint-maven-plugin</artifactId>
<versionRange>[0.0.11,)</versionRange>
<goals>
<goals><goal>check</goal></goals>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build> </project>
The error here is "${shadedClassifier}" shadedClassifier is red and the error is: "Cannot resolve symbol 'shadedClassifier'"
So I reinstalled maven with "mvn clean install" but it still doesn't work.
Maven has installed correctly with clean install but still I have these errors.
Please any help would be appriciated. I've been stuck on this for a week and I really want to learn machine learning.
I'm guessing maven isn't setup properly. I would ensure the IDE is up to date. Right clicking on the project in intellij and hitting reload is something I would consider doing. Same answer as here: Force Intellij IDEA to reread all maven dependencies
Related
I'm making a program with deep4j and I'm having libraries issues when I try to initialize the program. It is saying that I am not able to load the libraries besides the fact I seem to have set the library path manually in the Java code below.
Failed to load for libnd4jcpu: java.lang.UnsatisfiedLinkError: no libnd4jcpu in java.library.path
I've tried to manually set the library load path and it still doesn't work.
String libPathProperty = System.getProperty("java.library.path");
System.setProperty("java.library.path", libPathProperty + ":/users/<user>/.javacpp/cache");
System.out.println(System.getProperty("java.library.path"));
System.setProperty("org.bytedeco.javacpp.logger.debug","true");
My Pom I believe is following the steps from https://nd4j.org/getstarted. I'm posting it below.
<?xml version="1.0" encoding="UTF-8"?>
<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.example.com</groupId>
<version>0.1.0</version>
<name>Example</name>
<url>example.com</url>
<description>Example</description>
<artifactId>Examole</artifactId>
<packaging>jar</packaging>
<organization>
<name>example.com</name>
</organization>
<properties>
<!-- protobuf paths -->
<protobuf.input.directory>${project.basedir}/src/main/java/com/proto</protobuf.input.directory>
<protobuf.output.directory>${project.basedir}/src/main/java</protobuf.output.directory>
<project.build.dir>${project.basedir}/build</project.build.dir>
<!-- library versions -->
<build-helper-maven-plugin.version>1.9.1</build-helper-maven-plugin.version>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
<maven-shade-plugin.version>2.4.2</maven-shade-plugin.version>
<os-maven-plugin.version>1.4.1.Final</os-maven-plugin.version>
<protobuf.version>3.0.0</protobuf.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<nd4j.version>0.9.1</nd4j.version>
<arbiter.version>0.9.1</arbiter.version>
<!-- nlp versions -->
<stanfordnlp.version>3.9.1</stanfordnlp.version>
<outputDirectory>/users/example/workspace/examplet/build/classes</outputDirectory>
</properties>
<dependencies>
<!--Standard Packages-->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--NLP Packages-->
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${stanfordnlp.version}</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>${stanfordnlp.version}</version>
<classifier>models</classifier> <!-- will get the dependent model jars -->
</dependency>
<!--ML Packages-->
<dependency>
<groupId>nz.ac.waikato.cms.weka</groupId>
<artifactId>weka-stable</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>nz.ac.waikato.cms.weka</groupId>
<artifactId>LibSVM</artifactId>
<version>1.0.10</version>
</dependency>
<!--DL Packages-->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-nlp</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>${nd4j.version}</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>${nd4j.version}</version>
</dependency>
<dependency>
<groupId>org.datavec</groupId>
<artifactId>datavec-api</artifactId>
<version>1.0.0-alpha</version>
</dependency>
<!--BLAS is used as a backend for libnd4j computations-->
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>openblas</artifactId>
<version>0.2.20-1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.1</version>
</dependency>
<!--Tuning Packages-->
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>arbiter-ui_2.11</artifactId>
<version>${arbiter.version}</version>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>arbiter-deeplearning4j</artifactId>
<version>${arbiter.version}</version>
</dependency>
<!--Logging Packages-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
<build>
<extensions>
<!-- provides os.detected.classifier (i.e. linux-x86_64, osx-x86_64) property -->
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin.version}</version>
</extension>
</extensions>
<directory>${project.build.dir}/classes</directory>
<outputDirectory>${outputDirectory}</outputDirectory>
<plugins>
<!-- copy protoc binary into build directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>copy-protoc</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.google.protobuf</groupId>
<artifactId>protoc</artifactId>
<version>${protobuf.version}</version>
<classifier>${os.detected.classifier}</classifier>
<type>exe</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.dir}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- compile proto file into java files. -->
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.5.1.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<!-- <includeDirectories> <include>src/main/protobuf</include> </includeDirectories> -->
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
<!-- Create java files. And put them in the src/main/java directory. -->
<outputTargets>
<outputTarget>
<type>java</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
<!--compile proto buffer files using copied protoc binary-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<execution>
<id>exec-protoc</id>
<phase>generate-sources</phase>
<configuration>
<target>
<property name="protoc.filename" value="protoc-${protobuf.version}-${os.detected.classifier}.exe"/>
<property name="protoc.filepath" value="${project.build.dir}/${protoc.filename}"/>
<chmod file="${protoc.filepath}" perm="ugo+rx"/>
<mkdir dir="${protobuf.output.directory}" />
<path id="protobuf.input.filepaths.path">
<fileset dir="${protobuf.input.directory}">
<include name="**/*.proto"/>
</fileset>
</path>
<pathconvert pathsep=" " property="protobuf.input.filepaths" refid="protobuf.input.filepaths.path"/>
<exec executable="${protoc.filepath}" failonerror="true">
<arg value="-I"/>
<arg value="${protobuf.input.directory}"/>
<arg value="--java_out"/>
<arg value="${protobuf.output.directory}"/>
<arg line="${protobuf.input.filepaths}"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-shade-plugin</artifactId>-->
<!--<version>2.1</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>shade</goal>-->
<!--</goals>-->
<!--<configuration>-->
<!--<transformers>-->
<!--<transformer-->
<!--implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
<!--<mainClass>main.java.com.chatbot.Main</mainClass>-->
<!--</transformer>-->
<!--</transformers>-->
<!--</configuration>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.chatbot.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>${shadedClassifier}</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>org/datanucleus/**</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
But I keep running into errors in that it won't load the libraries. Here's my output currently:
> Loading class org.nd4j.nativeblas.Nd4jCpu
> Loading class org.nd4j.nativeblas.Nd4jCpu
> Loading library libnd4jcpu
> Failed to load for libnd4jcpu: java.lang.UnsatisfiedLinkError: no libnd4jcpu in java.library.path
> Loading /users/example/.javacpp/cache/nd4j-native-0.9.1-macosx-x86_64.jar/org/nd4j/nativeblas/macosx-x86_64/libnd4jcpu.dylib
> Loading /users/example/.javacpp/cache/nd4j-native-0.9.1-macosx-x86_64.jar/org/nd4j/nativeblas/macosx-x86_64/libjnind4jcpu.dylib
> Loading library libnd4jcpu
> Failed to load for libnd4jcpu: java.lang.UnsatisfiedLinkError: no libnd4jcpu in java.library.path
> Loading class org.bytedeco.javacpp.openblas
> Loading class org.bytedeco.javacpp.openblas
> Loading library iomp5
> Failed to load for iomp5: java.lang.UnsatisfiedLinkError: no iomp5 in java.library.path
> Loading library mkl_core
> Failed to load for mkl_core: java.lang.UnsatisfiedLinkError: no mkl_core in java.library.path
> Loading library mkl_avx
> Failed to load for mkl_avx: java.lang.UnsatisfiedLinkError: no mkl_avx in java.library.path
> Loading library mkl_avx2
> Failed to load for mkl_avx2: java.lang.UnsatisfiedLinkError: no mkl_avx2 in java.library.path ....
I can see that libnd4jcpu does exist, so I'm not sure what's the issue.
Computer: Macbook 2015 : No GPU
Update I ran the example MDPClassifer code from https://github.com/deeplearning4j/dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/feedforward/classification/MLPClassifierLinear.java and used the pom.xml file they had. I had the same problem
I have a collection of Java projects. It is a series of APIs. I am generating much of the server code from the swagger definition using swagger codegen. I'm using spring-boot with the delegate pattern, so my generated code all goes to src/gen/java/main and I can write my implementation code in src/main/java. The generated code is not version controlled, but re-generated as needed by the maven swagger codegen plugin. All this works nicely :)
However, when I first import the projects into Eclipse (using "import existing maven project" on the parent project to import them all) I get a bunch of "unused function" type warnings from the generated code. (I add the src/gen/java/main folder as a source folder using the build-helper-maven-plugin.) If I select the src/gen/java/main folder in each project, right-click, choose properties and say Ignore optional compile problems then this goes away (I also mark it as a derived resource)
Question: is there some way to mark this folder in the pom so that when I (or a colleague) imports the project into Eclipse, these settings are already set on that folder? Alternatively, some way to tell eclipse to always treat folders with the name (relative to project route) in that fashion?
Additional Info
I was asked for the pom file in a comment. I have done a fairly minimal example:
<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.example.api</groupId>
<artifactId>com.example.api</artifactId>
<packaging>jar</packaging>
<name>Example</name>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.7.0</springfox-version>
<swagger.codegen.version>2.4.0-SNAPSHOT</swagger.codegen.version>
<jetty-version>9.2.15.v20160210</jetty-version>
<slf4j-version>1.7.21</slf4j-version>
<junit-version>4.12</junit-version>
<servlet-api-version>2.5</servlet-api-version>
<springfox-version>2.7.0</springfox-version>
<jackson-version>2.8.9</jackson-version>
<jackson-threetenbp-version>2.6.4</jackson-threetenbp-version>
<spring-version>4.3.9.RELEASE</spring-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<versionRange>${swagger.codegen.version}</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.api.Swagger2SpringBoot</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Needed to create swagger bits in asynch manner -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger.codegen.version}</version>
<executions>
<execution>
<id>foo</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/spec/foo.yaml</inputSpec>
<modelPackage>com.example.api.models</modelPackage>
<apiPackage>com.example.api</apiPackage>
<language>spring</language>
<invokerPackage>com.example.api</invokerPackage>
<basePackage>com.example.api</basePackage>
<withXml>true</withXml>
<configOptions>
<artifactId>bookings</artifactId>
<artifactDescription>Bookings API</artifactDescription>
<title>Bookings API</title>
<artifactUrl>https://api.example.com/foo</artifactUrl>
<groupId>com.example.api</groupId>
<artifactVersion>1.0</artifactVersion>
<configPackage>com.example.api.config</configPackage>
<serializableModel>true</serializableModel>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<async>true</async>
<library>spring-boot</library>
<delegatePattern>true</delegatePattern>
<useBeanValidation>true</useBeanValidation>
<useOptional>true</useOptional>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<webAppConfig>
<contextPath>/v2</contextPath>
</webAppConfig>
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
<stopPort>8079</stopPort>
<stopKey>stopit</stopKey>
<httpConnector>
<port>8002</port>
<idleTimeout>60000</idleTimeout>
</httpConnector>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
This uses a minimal foo.yaml:
swagger: '2.0'
info:
title: Foo API
description: Test case
version: 1.0
host: api.example.com
basePath: /
schemes:
- https
consumes:
- application/json
produces:
- application/json
tags:
- name: foo
parameters:
message:
name: message
in: body
description: Foo
schema:
$ref: '#/definitions/Message'
required: true
definitions:
Message:
type: object
description: Foo
properties:
heading:
type: string
description: heading
body:
type: string
description: body
paths:
/foo:
post:
summary: foo
operationId: postFoo
tags:
- foo
parameters:
- $ref: '#/parameters/message'
responses:
'202':
description: Messages will be sent
default:
description: An unexpected error occurred
If I just mvn clean compile then import this the it's fine. However, if I add any implementation code that uses the generated code then it isn't.
For example, I added a package com.example.api.implementation to src/main/java containing a file FooApi.java which was:
package com.example.api.implementation;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import com.example.api.FooApiDelegate;
import com.example.api.models.Message;
import com.fasterxml.jackson.databind.ObjectMapper;
#Component
public class FooApi implements FooApiDelegate {
private final ObjectMapper objectMapper;
private final HttpServletRequest request;
public Optional<ObjectMapper> getObjectMapper() {
return Optional.ofNullable(objectMapper);
}
public Optional<HttpServletRequest> getRequest() {
return Optional.ofNullable(request);
}
#org.springframework.beans.factory.annotation.Autowired
public FooApi(ObjectMapper objectMapper, HttpServletRequest request) {
this.objectMapper = objectMapper;
this.request = request;
}
#Override
public CompletableFuture<ResponseEntity<Void>> postFoo( Message message) {
return new CompletableFuture<ResponseEntity<Void>>();
}
}
If I now import, I get errors FooApiDelegate cannot be resolved to a type and Message cannot be resolved to a type (and for the corresponding imports) from my non.generated file.
There are at least two issues. The first thing is that you explicitly suppressed the execution of the code generation by using org.eclipse.m2e.. this will suppress any kind of generation you might have. Furthermore you are using a 2.4.0-SNAPSHOT where you should use 3.0.0-rc0 instead. Unfortunately the 3.0.0-rc0 has failured so you should stick with 2.3.1 which is a release instead of SNAPSHOT's.
Apart from that the plugin is missing also things are not correctly handled...If you cleanly import the project in Eclipse you will get a dialog about Setup Maven Plugin Connectors. Furthermore the plugin does not correctly handle the update in Eclipse context which can be done...
If you import the project and manually add the source folders from target/generated-sources this will work but unfortunately not allways...
I've been trying to debug this issue for a bit now, and searching SO and other websites I haven't been able to find a solution. I've checked all versions of the dependencies in my pom.xml and made sure they are compatible with grizzly2, and I've also verified that it is being imported. However, Java is still printing out this error upon run:
Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.<init>(Ljavax/ws/rs/core/Application;Lorg/glassfish/hk2/utilities/Binder;)V
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:334)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:122)
at com.kyrahosting.daemon.Main.startServer(Main.java:30)
at com.kyrahosting.daemon.Main.main(Main.java:34)
Here is my pom.xml:
4.0.0
<groupId>com.kyrapanel.daemon</groupId>
<packaging>jar</packaging>
<name>KyraPanel Daemon</name>
<artifactId>KyraDaemon</artifactId>
<version>1.0-SNAPSHOT</version>
<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>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-all</artifactId>
<version>2.3.30</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- any other plugins -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.kyrahosting.daemon.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.17</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Any help will be appreciated!
Don't mix your Jersey versions
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.25.1</version>
</dependency>
Which one is different? Fix it.
And get rid of this
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-all</artifactId>
<version>2.3.30</version>
</dependency>
jersey-container-grizzly2-http already pulls in everything you need for Grizzly.
As an aside, the error says nothing about "GrizzlyHttpServerFactory doens't exist". It's saying that there is no such method (in this case constructor)
public ApplicationHandler(Application application, Binder binder) {}
That's how you read this
java.lang.NoSuchMethodError: org.glassfish.jersey.server.ApplicationHandler.<init>(Ljavax/ws/rs/core/Application;Lorg/glassfish/hk2/utilities/Binder;)V
The reason you would get this error when mixing versions is because say some class in Jersey 2.25.1 is trying to call the constructor mentioned above. But in version 2.9.1 this constructor doesn't exist. Say it wasn't added til a later version. But when loading classes, the ApplicationHandler from 2.9.1 is loaded, instead of the one from 2.25.1. So now you have the wrong ApplicationHandler version loaded. Hence the error; there's no such constructor.
I was facing an issue similar to the one asked here with my Spring Boot Application. My application was unable to find LocalizationMessages class under org.glassfish.jersey.internal in place of org.glassfish.jersey.server.ApplicationHandler. with the same error java.lang.NoSuchMethodError .
java.lang.NoSuchMethodError: org.glassfish.jersey.internal.LocalizationMessages.WARNING_PROPERTIES()Ljava/lang/String
2021-09-20 15:27:47.927 INFO 11 --- [http-nio-9070-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.glassfish.jersey.internal.LocalizationMessages.WARNING_PROPERTIES()Ljava/lang/String;] with root cause
The irony is that the same set of dependencies worked fine on a java maven project. On getting the dependency tree mvn dependency:tree for java project I was able to get class org.glassfish.jersey.internal.LocalizationMessages but it was missing on the dependency tree for Spring Boot Project.
Following Issues observed:
The Jar created by Spring Boot was not containing the dependency when I was using spring-boot-maven-plugin with version 2.4.3
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.3</version>
</plugin>
When I was trying to create a shaded jar with the above version then I was getting error for all the Transformer implementation I was using. Error ex: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ServicesResourceTransformer
I changed the version to 1.5.8.RELEASE and then the shaded jar compilation went through.
I replaced the default Spring Boot Application Plugin with the shaded jar Plugin.
Default Spring Boot Application Plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
<configuration>
<mainClass>com.rohit.agrawal.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Shaded Jar Plugin I used to resolve error
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
</dependency>
</dependencies>
<configuration>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.rohit.agrawal.Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-version}</version>
</plugin>
</plugins>
</build>
Please see that here spring-boot-version is 1.5.8.RELEASE
Now the Jar has the required class:
rohiagra-mac:faw-qa-api rohiagra$ jar -tvf target/faw-qa-api-1.0-SNAPSHOT.jar | grep "org.glassfish.jersey.internal.LocalizationMessages"
42097 Tue Sep 21 18:01:54 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages.class
268 Tue Sep 21 18:01:56 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages$1.class
1272 Tue Sep 21 18:01:56 IST 2021 BOOT-INF/classes/org/glassfish/jersey/internal/LocalizationMessages$BundleSupplier.class
In Dec.2017, this set of Maven dependencies worked fine for me to start Jetty with RS.
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>9.4.8.v20171121</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.26-b03</version>
</dependency>
I have created multi-module CQ5 Maven project. My Cq version is 5.5 and Java version is 6.
These are the steps that I have followed.
Created maven multi-module CQ maven project
Imported it in eclipse
Used VLT to import an existing project from repository into maven.
Converted the project to faceted form so the bundle part works fine.
In the content module I am trying to use JspC Plugin I have added the correct plugin info and dependencies in the respective POM files.
The Problem is that when I compile JspC says that global.jsp is not found
So I imported /libs also in my project and made sure that the libs is not included in built. By excluding the /libs folder. I referred this link Adding /libs
My JSPs have the default autocomplete feature in them but they don't recognise any CQ objects like the ones defined in <cq:defineObjects /> WHY ??
I referred this Link Autocomplete in JSP
My Directory Structure
My Content POM is as follows
<?xml version="1.0" encoding="UTF-8"?>
<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>
<!-- ====================================================================== -->
<!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<parent>
<groupId>supplierportal</groupId>
<artifactId>supplierportal</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>
<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<artifactId>supplierportal-content</artifactId>
<packaging>content-package</packaging>
<name>Supplier Portal Package</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>supplierportal-bundle</artifactId>
<version>${project.version}</version>
</dependency>
<!-- My Dependencies -->
<!-- Dependencies for Maven JSPC Starts -->
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.jcr-wrapper</artifactId>
<version>2.0.0</version>
<!-- javax.jcr -->
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.day.cq</groupId>
<artifactId>cq-commons</artifactId>
<version>5.5.0</version>
<!-- com.day.cq.commons -->
</dependency>
<dependency>
<groupId>com.day.cq.wcm</groupId>
<artifactId>cq-wcm-commons</artifactId>
<version>5.5.2</version>
<!-- com.day.cq.wcm.commons -->
</dependency>
<dependency>
<groupId>com.day.cq.wcm</groupId>
<artifactId>cq-wcm-api</artifactId>
<version>5.5.0</version>
<!-- com.day.cq.wcm.api -->
</dependency>
<dependency>
<groupId>com.day.commons</groupId>
<artifactId>day-commons-jstl</artifactId>
<version>1.1.4</version>
<!-- javax.servlet.jsp.jstl.core -->
</dependency>
<dependency>
<groupId>com.day.cq.wcm</groupId>
<artifactId>cq-wcm-taglib</artifactId>
<version>5.5.0</version>
<!-- com.day.cq.wcm.tags -->
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.jsp.taglib</artifactId>
<version>2.2.0</version>
<!-- org.apache.sling.scripting.jsp.taglib -->
</dependency>
<dependency>
<groupId>com.adobe.granite</groupId>
<artifactId>com.adobe.granite.xssprotection</artifactId>
<version>5.5.14</version>
<!-- com.adobe.granite.xss -->
</dependency>
<dependency>
<groupId>com.day.cq.wcm</groupId>
<artifactId>cq-wcm-core</artifactId>
<version>5.5.6</version>
<!-- com.day.cq.wcm.core.components -->
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
<!-- org.apache.commons.lang3 -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
</dependency>
<!-- Ends -->
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/content/jcr_root</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/.vlt</exclude>
<exclude>**/.vltignore</exclude>
<exclude>libs/</exclude>
</excludes>
</resource>
</resources>
<!-- Autocomplete Plugin config comes here -->
<!-- THis is Completely different Stuff... An Attempt to bring autocomplete feature in JSP -->
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.sling</groupId>
<artifactId>maven-jspc-plugin</artifactId>
<versionRange>[2.0.6,)</versionRange>
<goals>
<goal>jspc</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<versionRange>[2.4.1,)</versionRange>
<goals>
<goal>clean</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<!-- Autocomplete Ends -->
<!-- Ends Autocomplete -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</plugin>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<group>supplierportal</group>
<filterSource>src/main/content/META-INF/vault/filter.xml</filterSource>
<embeddeds>
<embedded>
<groupId>${project.groupId}</groupId>
<artifactId>supplierportal-bundle</artifactId>
<target>/apps/supplierportal/install</target>
</embedded>
</embeddeds>
<targetURL>http://${crx.host}:${crx.port}/crx/packmgr/service.jsp</targetURL>
</configuration>
</plugin>
<!-- Here I add code for JSPc Plugin -->
<!-- start -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/jsps-to-compile</outputDirectory>
<resources>
<resource>
<directory>src/main/content/jcr_root</directory>
<excludes>
<exclude>libs/**</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-jspc-plugin</artifactId>
<version>2.0.6</version>
<executions>
<execution>
<id>compile-jsp</id>
<goals>
<goal>jspc</goal>
</goals>
<configuration>
<jasperClassDebugInfo>false</jasperClassDebugInfo>
<sourceDirectory>${project.build.directory}/jsps-to-compile</sourceDirectory>
<outputDirectory>${project.build.directory}/ignoredjspc</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>remove-compiled-jsps</id>
<goals>
<goal>clean</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.build.directory}/jsps-to-compile</directory>
<directory>${project.build.directory}/ignoredjspc</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<!-- end -->
<!-- Ends JSPC plugin config -->
</plugins>
</build>
<profiles>
<profile>
<id>autoInstallPackage</id>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-content-package</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>autoInstallPackagePublish</id>
<build>
<plugins>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<executions>
<execution>
<id>install-content-package-publish</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
<configuration>
<targetURL>http://${publish.crx.host}:${publish.crx.port}/crx/packmgr/service.jsp</targetURL>
<username>${publish.crx.username}</username>
<password>${publish.crx.password}</password>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
#Vincent I couldn't answer you question in comments so I am giving you a detailed answer to you comment here.
To import /lib/foundations you have a create an EXTRA file filter-vlt.xml under
{yourproject}\content\src\main\content\META-INF\vault\filter-vlt.xml
In filter-vlt.xml this you have to enter
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/libs/foundation"/>
<filter root="/apps/myapp"/>
<filter root="/etc/designs/myapp"/>
<filter root="/etc/designs/bootstrap-custom-version2"/>
</workspaceFilter>
See entry of /libs/foundation.
Make sure you don't put this entry in filter.xml. This should be present in filter-vlt.xml
And your filter.xml entry will be like this.
<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
<filter root="/apps/myapp"/>
<filter root="/etc/designs/myapp"/>
<filter root="/etc/designs/bootstrap-custom-version2"/>
</workspaceFilter>
i.e the /libs/foundation is not present in filter.xml
Then browse to {yourproject}\content\src\main\content\jcr_root and type
vlt up --force
This will import you /apps/myapp i.e your project into your file system along with
/libs/foundation but when you are building your project /libs/foundation will not be included in the build.
Conclusion:
filter-vlt.xml helps you import files from CQ repo to local drive(file system) that you need for compiling your project. But these files are not included when you do maven build or install into CQ repository(filesystem to CQ repo).
Only those files are pushed into CQ repository whose entry is present in filter.xml
I got it. I imported /libs/foundation in my content part of Maven project.
Then I added this in the maven-resources-plugin configuration
<resource>
<directory>src/main/content/jcr_root</directory>
<includes>
<include>apps/**</include>
<include>libs/foundation/global.jsp</include>
</includes>
</resource>
This configuration includes global.jsp in the compile process, so this helped all my Jsps that had included global.jsp in them to compile successfuly.
But it is also necessary to exclude the libs in the built other wise the whole /libs is included in the built.
To do that we must add this entry in content/pom.xml
<build>
<resources>
<resource>
<directory>src/main/content/jcr_root</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/.vlt</exclude>
<exclude>**/.vltignore</exclude>
<exclude>libs/</exclude>
</excludes>
</resource>
</resources>
Hi I've got a basic Jersey Client that I'm trying to run with a main() in my "main" java class. It compiles fine in Eclipse, but when I try to run it as java application, I get:
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
Can anyone tell me what I'm doing wrong? Here's 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>ca.ubc.iamwsClient</groupId>
<artifactId>iamwsClient</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>iamwsClient</name>
<properties>
<jersey.version>2.5.1</jersey.version>
<target.dir>target</target.dir>
<project.build.directory>target</project.build.directory>
</properties>
<repositories>
<repository>
<id>JBoss Repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<!-- jackson dependencies for pojo/json support -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-processing</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- end jackson deps -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId>
<version>1.8</version> </dependency> -->
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId>
<version>1.1</version> </dependency> -->
</dependencies>
<build>
<finalName>iamwsClient</finalName>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>ca.ubc.iamwsClient.IamwsClient</mainClass>
</configuration>
</plugin> -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>ca.ubc.iamwsClient.IamwsClient</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.1,)
</versionRange>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Client that I'm trying to run:
package ca.ubc.iamwsClient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.jackson.JacksonFeature;
import ca.ubc.iamwsClient.json.CreateEmployeeBean;
import ca.ubc.iamwsClient.json.CreateEmployeeResponseBean;
/**
* Main class.
*
*/
public class IamwsClient {
private WebTarget getTarget(String targetUrl) throws Exception {
// create the client
Client c = ClientBuilder.newClient().register(JacksonFeature.class);
return c.target(targetUrl);
}
public CreateEmployeeResponseBean sendCreateEmployeeRequest(CreateEmployeeBean createBean, String url) {
CreateEmployeeResponseBean rb = null;
try {
WebTarget target = getTarget(url);
WebTarget wt = target.path("employeeAutoCreate");
WebTarget generateTarget = wt.path("generate");
rb = generateTarget.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(createBean,MediaType.APPLICATION_FORM_URLENCODED_TYPE),
CreateEmployeeResponseBean.class);
System.out.println("CreateEmployee: generate response: success=" + rb.getSuccess() + " message=" + rb.getMessage());
} catch (Throwable t) {
t.printStackTrace();
System.out.println("*********EXCEPTION THROWN: " + t.getMessage());
}
return rb;
}
public static void main(String[] args) {
String testUrl="http://localhost:9090/iamws";
CreateEmployeeBean bean = new CreateEmployeeBean();
// ... set some details on bean....
IamwsClient client = new IamwsClient();
CreateEmployeeResponseBean response = client.sendCreateEmployeeRequest(bean, testUrl);
if (response != null) {
System.out.println("*********server responded with flag: " + response.getSuccess() + " message: " + response.getMessage());
}
}
}
You need to make sure that the JAR dependency containing org.glassfish.jersey.client.JerseyClientBuilder class is available on your application's classpath during the run time. There's really no other explanation to NoClassDefFound error.
From what I can google on this class, it should be available in
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.0-m04</version>
</dependency>
In other words your com.sun.jersey dependency may be missing it.
EDIT
This is the actual answer which the OP added to the Question afterwards:
<jersey.version>2.5.1</jersey.version>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-processing</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
He already had org.glassfish.jersey.core and org.glassfish.jersey.connectors. He removed com.sun.jersey dependency.
I am going to try this myself shortly.