In my maven project, i have the below dependencies:
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>3.4.1</version>
</dependency>
and then, i have a very basic code just to open an app:
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
File f = new File("src");
File fs = new File(f,"ApiDemos-debug.apk");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "myAVD");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement> ad = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
But, it complains with the below error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/internal/ApacheHttpClient$Factory
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:50)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:77)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:67)
at Appium.Appium.App.main(App.java:30)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.ApacheHttpClient$Factory
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
Are my dependencies wrong?
How can i fix it?
The first thing to keep in mind: don't mix selenium & appium dependencies. Appium already has selenium dependency and explicitly setting one you may cause an issue.
The other reasonable question: you are using quite an old client version, the current one is 7.3.0 Check what Appium server you got installed and if it is 1.15.x+ you probably need to use fresh client as well.
Related
I am trying to integrate AWS SNS in my maven project. I get below error while deploying the code
Could not start bundle aem-myproject.core [622]. Reason: {}. Will retry.
org.osgi.framework.BundleException: Unable to resolve aem-myproject.core [622](R 622.69): missing requirement [aem-myproject.core [622](R 622.69)] osgi.wiring.package; (osgi.wiring.package=software.amazon.awssdk.auth.credentials) Unresolved requirements: [[aem-myproject.core [622](R 622.69)] osgi.wiring.package; (osgi.wiring.package=software.amazon.awssdk.auth.credentials)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4368)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2281)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)
at org.apache.sling.installer.core.impl.tasks.BundleStartTask.execute(BundleStartTask.java:97) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.doExecuteTasks(OsgiInstallerImpl.java:914) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.executeTasks(OsgiInstallerImpl.java:749) [org.apache.sling.installer.core:3.9.0.B002]
at org.apache.sling.installer.core.impl.OsgiInstallerImpl.run(OsgiInstallerImpl.java:298) [org.apache.sling.installer.core:3.9.0.B002]
at java.base/java.lang.Thread.run(Thread.java:834)
I have added below two dependencies in my POM file,
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-sdk-java</artifactId>
<version>2.20.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/auth -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<version>2.20.2</version>
</dependency>
But I am not sure why it could not resolve software.amazon.awssdk.auth.credentials. Can anyone tell me if I need any other dependency to resolve this?
Ref - https://github.com/aws/aws-sdk-java-v2/#using-the-sdk
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-simple-notification-service.html
Basically I want to get all below import statement classes,
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.CreateTopicRequest;
import software.amazon.awssdk.services.sns.model.CreateTopicResponse;
import software.amazon.awssdk.services.sns.model.SnsException;
Have you specified scope below on purpose?
<scope>provided</scope>
"provided" dependency should be provided by application server / servlet container.
If they are not provided, the deployment will fail. Try to change scope to compile to make the dependency a part of a package.
I am trying to connect to Firebase within my Java project, managed with Maven. I am following Firebase's Getting Started with Cloud Firestore exactly to set up my development environment and initialize Cloud Firestore. This is what my pom.xml and myClass.java looks like.
My dependency in pom.xml:
<dependencies>
<!-- This dependency is added for Firebase usage -->
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>7.1.0</version>
</dependency>
My myClass.java:
package ca.uhn.fhir.example;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.Firestore;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import java.io.*;
#WebServlet("/*")
public class Example02_SimpleRestfulServer extends RestfulServer {
#Override
protected void initialize() throws ServletException {
// Create a context for the appropriate version
setFhirContext(FhirContext.forR4());
// Register resource providers
// Calls the constructor on the resource provider class?
registerProvider(new Example01_PatientResourceProvider());
// Format the responses in nice HTML
registerInterceptor(new ResponseHighlighterInterceptor());
try {
// Initialize Firebase
// Use a service account
String credentials_path = "/my/path/dfdfdfdfd93.json";
InputStream serviceAccount = new FileInputStream(credentials_path);
GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(credentials)
.build();
FirebaseApp.initializeApp(options);
Firestore db = FirestoreClient.getFirestore();
}
catch (IOException e) {
e.printStackTrace();
}
However, I run into the error:
cannot find symbol [ERROR] symbol: variable FirestoreClient. I have tried adding other related dependencies as shown below, but they are not found/don't seem to fix the problem. I think I am following the Firebase tutorial exactly, so what might I be doing wrong? Why is the FirestoreClient not recognized but many of the other variables are?
<!-- Attempting to fix errors (this doesn't seem to do anything) -->
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-firestore -->
<!-- <dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>2.2.4</version>
</dependency> -->
<!-- Not found -->
<!-- https://mvnrepository.com/artifact/com.google.firebase/firebase-firestore -->
<!-- <dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-firestore</artifactId>
<version>18.1.0</version>
</dependency> -->
<!--Not found-->
<!-- https://mvnrepository.com/artifact/com.google.firebase/firebase-core -->
<!-- <dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-core</artifactId>
<version>18.0.2</version>
</dependency> -->
This is happening because you did not import the FirestoreClient class, so add the following import to your Example02_SimpleRestfulServer class and it will be fixed:
import com.google.firebase.cloud.FirestoreClient;
NOTE: This should also be in the example in the documentation example you shared, I would recommend you to open a Bug Report in Google's IssueTracker for they to fix that documentation, if you'd like.
I tried maven repo like this:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>2.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-yarn-api -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-api</artifactId>
<version>2.7.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-yarn-client -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
<version>2.7.2</version>
</dependency>
Then my java code:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.ApplicationConstants;
import org.apache.hadoop.yarn.api.records.*;
import org.apache.hadoop.yarn.client.api.YarnClient;
import org.apache.hadoop.yarn.client.api.YarnClientApplication;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
public static void main(String[] args) {
YarnConfiguration yarnConfiguration = new YarnConfiguration();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(yarnConfiguration);
yarnClient.start();
}
Intellij ide shows "Cannot solve method init" and "Cannot solve method start".
I then tried to use jar version of 3.1.1 instead of "2.7.2". Same result. So what's wrong with my code and how to fix it?
the init and start method are derived from the AbstractService class.
you need to verify the YarnClient and AbstractService has the same version.
go to YarnClient and check the jar it refer to, then click on the AbstractService parent from the Yarn client and check his version.
change the YarnClient version according to your AbstractService version.
i had the same issue, it works for me . version 2.6.5 .
I want to run headless Chrome with Selenium, but this code not works:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
File file = new File("/usr/bin/chromedriver");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver(chromeOptions);
It compiles fine, but at runtime crashes with stacktrace:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:62)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:39)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:184)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:171)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:158)
at org.chrome.automation.Starter.main(Starter.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
The POM contains just two dependencies:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
I thought the problem in Selenium dependencies, as they are rely on some apache code but not download dependent components. I tried to add apache dependencies like:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
</dependency>
But problem persists.
Please help to run selenium with headless Crome.
I was able to resolve by using just one dependency:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.1</version>
</dependency>
Also it works with 3.3.1, 3.2.0. As I see the problem happen in 3.4.0 version only.
I faced the same issue, not only with chrome but with other browses too.
seems, there were some jars missing, do following and it should fix the issue:
Close the eclipse
Go to "C:\Users\myuser.m2\repository" folder and delete all the files and folder from here
Open elclipse, select your project and do alt+f5 and check option Force Update of Snapshots.
Wait till it builds, it should be fixed now.
Worked for me.
Specifying explicit dependency on selenium-chrome-driver is definitely wrong, as selenium-java already contains this.
To get Chrome running in headless mode, you need Chrome minimum version 59 (version 60 on Windows), and the following code:
System.setProperty("webdriver.chrome.driver", ...);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless", "disable-gpu");
WebDriver driver = new ChromeDriver(chromeOptions);
disable-gpu is required as an option; see this discussion for more details.
I'm trying to run a face recognition example using javacv, but there is a mismatch in the methods arguments types.
I'm using the following maven dependencies:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.0.0-1.1</version>
</dependency>
<dependency>
I'm referring to this example: http://pcbje.github.io/misc/2012/12/01/doing-face-recognition-with-javacv.html
Imports:
import static org.bytedeco.javacpp.opencv_face.createFisherFaceRecognizer;
import static org.bytedeco.javacpp.opencv_imgproc.CV_BGR2GRAY;
import static org.bytedeco.javacpp.opencv_imgproc.cvCvtColor;
import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_8U;
import java.io.File;
import java.io.FilenameFilter;
import org.bytedeco.javacpp.opencv_core.IplImage;
import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_core.MatVector;
import org.bytedeco.javacpp.opencv_face.FaceRecognizer;
The only difference is that they are using com.googlecode.javacv, but as far as I understand this is old. However I downloaded those jars from http://www.java2s.com/Code/Jar/j/Downloadjavacvjar.htm, but I'm still not able to compile successfully.
Can you please advice. Thank you.
[SOLVED] - Please refer to this example