Jersey client javax.ws.rs.client.Client not found - java

I have a jersey client. I have the following imports in the client class
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
When I compile the application I get
./src/com/uciext/ws/class2/client/StudentClient.java:3: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
How can I fix the issue
EDITED:
This is the error trace
./src/com/uciext/ws/hw2/client/InventoryClient.java:4: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Client;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:5: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.ClientBuilder;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:6: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Entity;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:7: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.Invocation;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:8: error: package javax.ws.rs.client does not exist
import javax.ws.rs.client.WebTarget;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:9: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.MediaType;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:10: error: package javax.ws.rs.core does not exist
import javax.ws.rs.core.Response;
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: class Client
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:15: error: cannot find symbol
Client client = ClientBuilder.newClient();
^
symbol: variable ClientBuilder
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:16: error: cannot find symbol
WebTarget myResource = client.target("http://127.0.0.1:8080/inventory/rest/catalog");
^
symbol: class WebTarget
location: class InventoryClient
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: package Invocation does not exist
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
./src/com/uciext/ws/hw2/client/InventoryClient.java:17: error: cannot find symbol
Invocation.Builder builder = myResource.request(MediaType.TEXT_PLAIN);
^
symbol: variable MediaType
location: class InventoryClient
12 errors
This is the c.sh. I use jersey 2.2.7. I downloaded jersey 2.2.7 and copied it in my lib folder. Can I have the wrong version of jar.
JAXB_PATH=./lib/jaxb-ri-2.2.7/lib
JAXB_LIB=$JAXB_PATH/jaxb-api.jar:$JAXB_PATH/jaxb-core.jar:$JAXB_PATH/jaxb-impl.jar:$JAXB_PATH/jaxb-jxc.jar:$JAXB_PATH/jaxb-xjc.jar
JAXRS_PATH=./lib/jaxrs-ri/lib
JAXRS_API=./lib/jaxrs-ri/api
JAXRS_LIB=$JAXRS_PATH/jersey-server.jar:$JAXRS_PATH/jersey-common.jar:$JAXRS_PATH/jersey-container-servlet.jar:$JAXRS_PATH/jersey-container-servlet-core.jar:$JAXRS_API/javax.ws.rs-api-2.0.jar
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/api
CLASSPATH=$CLASSPATH:./lib/jaxb-ri-2.2.7/lib
CLASSPATH=$CLASSPATH:./lib/jaxrs-ri/lib
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/util/*.java ./src/com/uciext/ws/hw2/backend/model/*.java ./src/com/uciext/ws/hw2/backend/*.java ./src/com/uciext/ws/hw2/backend/impl/*.java ./src/com/uciext/ws/hw2/service/model/catalog/*.java ./src/com/uciext/ws/hw2/service/model/order/*.java ./src/com/uciext/ws/hw2/service/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/service/*.java ./src/com/uciext/ws/hw2/service/impl/*.java
javac -classpath $JAXB_LIB:$JAXRS_LIB:. -d classes ./src/com/uciext/ws/hw2/client/model/catalog/*.java ./src/com/uciext/ws/hw2/client/model/order/*.java ./src/com/uciext/ws/hw2/client/model/orderconfirm/*.java ./src/com/uciext/ws/hw2/client/*.java

Have you included the dependencies to get the implementation of this package?
If you are using maven this post give the details.
For library version, download libraries from here and follow the following tutorial for adding the required jars. Although the Client class is available in jaxrs-ri\api jar.

You want to grab this zip file and make sure the jaxrs-ri/api/jakarta.ws.rs-api-2.1.6.jar is in your classpath.

Related

How to run a java class in Eclipse (part of a maven project with a pom file) from cmd

I have a maven project (folder ev) and I want to run a java class (ChargerLocation.java) from the cmd. I 've tried the link but didn't work. When I run the ChargerLocation.java from Eclipse it works but I want to run it from the cmd.
It looks like that I should be able to run by: Run Configurations->Show Command Line and paste that in my cmd, however I get the following error'-classpath' is not recognized as an internal or external command, operable program or batch file.
In order to do the: Run Configurations->Show Command Line-> paste in cmd, in which folder should I be located?
I was wondering whether the command at the cmd should be something like Maven/apache-maven-3.6.3/bin/mvn exec:java -Dexec.mainClass="" since it's a maven project as a whole? Or it doesn't matter?
By simply doing javac ChargerLocation.java I get 45 errors which seem to be like it cannot find the proper libraries to build.
ChargerLocation.java:14: error: package org.matsim.api.core.v01 does not exist
import org.matsim.api.core.v01.Coord;
^
ChargerLocation.java:15: error: package org.matsim.api.core.v01 does not exist
import org.matsim.api.core.v01.Id;
^
ChargerLocation.java:16: error: package org.matsim.api.core.v01 does not exist
import org.matsim.api.core.v01.Scenario;
^
ChargerLocation.java:17: error: package org.matsim.api.core.v01.network does not exist
import org.matsim.api.core.v01.network.Link;
^
ChargerLocation.java:18: error: package org.matsim.api.core.v01.network does not exist
import org.matsim.api.core.v01.network.Network;
^
ChargerLocation.java:19: error: package org.matsim.contrib.ev.charging does not exist
import org.matsim.contrib.ev.charging.ChargeUpToMaxSocStrategy;
^
ChargerLocation.java:20: error: package org.matsim.contrib.ev.charging does not exist
import org.matsim.contrib.ev.charging.ChargingLogic;
^
ChargerLocation.java:21: error: package org.matsim.contrib.ev.charging does not exist
import org.matsim.contrib.ev.charging.ChargingWithQueueingLogic;
^
ChargerLocation.java:22: error: package org.matsim.contrib.ev.infrastructure does not exist
import org.matsim.contrib.ev.infrastructure.Charger;
^
ChargerLocation.java:23: error: package org.matsim.contrib.ev.infrastructure does not exist
import org.matsim.contrib.ev.infrastructure.ChargerImpl;
^
ChargerLocation.java:24: error: package org.matsim.contrib.ev.infrastructure does not exist
import org.matsim.contrib.ev.infrastructure.ChargerSpecification;
^
ChargerLocation.java:25: error: package org.matsim.contrib.ev.infrastructure does not exist
import org.matsim.contrib.ev.infrastructure.ChargerWriter;
^
ChargerLocation.java:26: error: package org.matsim.contrib.ev.infrastructure does not exist
import org.matsim.contrib.ev.infrastructure.ImmutableChargerSpecification;
^
ChargerLocation.java:27: error: package org.matsim.core.config does not exist
import org.matsim.core.config.Config;
I also attach a photo of my folders in eclipse.
Finally, I want to call this java file from Python, so what I am trying to do here is: open cmd from Python (os.system()) with pre-written command to call java Class (ChargerLocation.java) and finally run the java class.
Thanks in advance
#howlger here is the command line I get from eclipse.
It's not the arguments that increase the number of characters but the different jar libraries that needs to be build first before running my main java file org.matsim.contrib.ev.example.ChargerLocation
As far as I understand the argfile is to write arguments, which in my case there aren't any.

Compiling Hadoop wordcount tutorial - hadoop 2.6.3

The following is my system configuration: windows8.1, vmware v12, 2 centOS VMs. I have installed hadoop on my VMs, one as master and the other as slave1. The services are correctly up and running on both nodes.
I want to compile my first mapreduce program, the wordcount tutorial:
I'm trying to compile using the following:
[hadoop#master ~]$ javac -classpath $HADOOP_HOME/share/common/hadoop-common-2.6.3.jar:$HADOOP-HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.3.jar:$HADOOP_HOME/share/common/lib/common-cli-1.2.jar -d /home/hadoop *.java
but the answer I get is this:
WordCount.java:4: error: package org.apache.hadoop.conf does not exist
import org.apache.hadoop.conf.Configuration;
^
WordCount.java:5: error: package org.apache.hadoop.fs does not exist
import org.apache.hadoop.fs.Path;
^
WordCount.java:6: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.IntWritable;
^
WordCount.java:7: error: package org.apache.hadoop.io does not exist
import org.apache.hadoop.io.Text;
^
WordCount.java:8: error: package org.apache.hadoop.mapreduce does not exist
(.
.
.) ^
symbol: class Path
location: class WordCount
WordCount.java:58: error: cannot find symbol
FileOutputFormat.setOutputPath(job, new Path(args[1]));
^
symbol: variable FileOutputFormat
location: class WordCount
40 errors
I googled and everyone said it's due to $CLASSPATH.
this is my /etc/bashrc file:
export JAVA_HOME=/opt/jdk
export JRE_HOME=/opt/jdk/jre
export PATH=$PATH:/opt/jdk/bin:/opt/jdk/jre/bin
export HADOOP_CLASSPATH=$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/opt/hadoop/
export CLASSPATH=$CLASSPATH:$HADOOP_HOME/share/common/hadoop-common-2.6.3.jar:$HADOOP-HOME/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.6.3.jar:$HADOOP_HOME/share/common/lib/common-cli-1.2.jar
any idea why I get this error?? I see no problem... :(
According to the documentation you can do the following (tested on my system and works)
export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar
$HADOOP_HOME/bin/hadoop com.sun.tools.javac.Main WordCount.java
and finally create the jar using
jar cf wc.jar WordCount*.class
link to the official doc here

Javac compilation error

I am trying to compile a Java class but I get this error:
TestRunner.java
TestRunner.java:3: error: package org.junit.runner does not exist
import org.junit.runner.JUnitCore;
^
TestRunner.java:4: error: package org.junit.runner does not exist
import org.junit.runner.Result;
^
TestRunner.java:5: error: package org.junit.runner.notification does not exist
import org.junit.runner.notification.Failure;
^
TestRunner.java:9: error: cannot find symbol
Result result = JUnitCore.runClasses(ApplicationIT.class);
^
symbol: class Result
location: class TestRunner
TestRunner.java:9: error: cannot find symbol
Result result = JUnitCore.runClasses(ApplicationIT.class);
It is unable to resolve any of the import packages and classes.
I'm not sure what is wrong?
Thanks
Got the same error, but
Closing android studio,cleaning the build and again rebuilding it solved my error.

Apache Spark Mllib Fp-growth Function not found Java

I'm new with spark, and I want to use the Fp Growth found in Mllib with java and maven. But I get this error during the compilation:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/cjd/fpgexample/src/main/java/org/fpgexample/FpgTest.java:[25,7] cannot find symbol
symbol: class Function
location: class org.fpgexample.FpgTest
this are the imports and the error line:
package org.fpgexample;
import java.util.Arrays;
import java.util.List;
import org.apache.spark.SparkConf;
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;
JavaRDD<List<String>> transactions = data.map( new Function<String, List<String>>() {`
I update the maven compiler to the 3.3 (using JDK 1.7), and spark-core and mllib 2.11 (1.5.1) versions. (with the mllib 2.10 1.4 maven didn't recognize the fpm.AssociationRules).
EDIT: I changed the maven compiler, pom.xml and JDK to 1.8 from 1.7, but the error persist.
You should import the correct package as below:
import org.apache.spark.api.java.function.Function;

Unable to compile a JUnit test on Windows

I'm trying to compile this very simple JUnit test on my Windows 10 box:
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class TestHelloWorld
{
#Test
public void BasicTest ()
{
assertTrue(true);
}
}
However, this seemingly innocuous task has proven impervious to three to four hours of research and trial and error.
From a Cygwin terminal I see this:
javac -cp lib/hamcrest-core-1.3.jar:/lib/junit-4.12.jar:. TestHe
TestHelloWorld.java:1: error: package org.junit does not exist
import static org.junit.Assert.assertTrue;
^
TestHelloWorld.java:1: error: static import only from classes and interfaces
import static org.junit.Assert.assertTrue;
^
TestHelloWorld.java:2: error: package org.junit does not exist
import org.junit.Test;
^
TestHelloWorld.java:6: error: cannot find symbol
#Test
^
symbol: class Test
location: class TestHelloWorld
TestHelloWorld.java:9: error: cannot find symbol
assertTrue(true);
^
symbol: method assertTrue(boolean)
location: class TestHelloWorld
5 errors
and from a CMD prompt I see this:
javac -cp C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar TestHelloWorld.java
error: error reading C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar; error in opening zip file
1 error
I honestly have no idea what I'm doing incorrectly here. I've always been on a *nix machine before, where I don't recall having any problems compiling JUnit tests when I pass in the junit and hamcrest jars to the class path using the -cp flag. Any ideas or guidance here would be much appreciated!
There are two thing:
Java in windows using ';' to separate the jar files in classpath argument so it should be
"javac -cp lib/hamcrest-core-1.3.jar;/lib/junit-4.12.jar;. TestHeTestHelloWorld.java" in cygwin
check if C:\Users\canon\Documents\GitHub\cse1341\AssignmentTester\lib\junit.jar is a valid jar. (you can use zip tool to check).
The slash before lib/junit-4.12.jar seems to be wrong.

Categories