I'm testing joss javaswift following this link. I also added JAR files from here to my project. But it provides an error. What am I doing wrong?
package test;
import org.javaswift.joss.client.factory.AccountConfig;
import org.javaswift.joss.client.factory.AccountFactory;
import org.javaswift.joss.model.Account;
public class Test {
public static void main(String[] args)
{
String username = "user";
String password = "pwd";
String authUrl = "http://...";
String tenantName = "test";
AccountConfig config = new AccountConfig();
config.setUsername(username);
config.setPassword(password);
config.setAuthUrl(authUrl);
config.setTenantName(tenantName);
Account account = new AccountFactory(config).createAccount();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/http/conn/scheme/SchemeSocketFactory at
org.javaswift.joss.client.factory.AccountFactory.createClientImpl(AccountFactory.java:38)
at
org.javaswift.joss.client.factory.AccountFactory.createAccount(AccountFactory.java:28)
at test.TestSWIFT3.main(TestSWIFT3.java:23)
Caused by: java.lang.ClassNotFoundException:
org.apache.http.conn.scheme.SchemeSocketFactory at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more
I think that you have a problem with the dependencies of the project.
Generally speaking, you need to create a project and in the project create a pom file for download the dependencies dynamically using maven.
The structure of the project should have a pom.xml file in the general configuration.
The pom file should contain at minimum the next information.
<?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>groupId</groupId>
<artifactId>testJoss</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.javaswift</groupId>
<artifactId>joss</artifactId>
<version>0.9.7</version>
</dependency>
</dependencies>
</project>
The first line is the definition required for the pom in the project.
I create an example project with the proper libraries.
https://bitbucket.org/stackoverflowquestion/testjoss/src/b6f930cd02d85ec71c27d5560ca2fe34097ce4d4?at=master
The example project works fine and the issue with the libraries is not present. The example have the debug activated, so, it is possible to see if everything goes well.
Related
I'm trying to use jax-rs 2.0 for an existing java client code (java 8), it didn't previously support maven (and i do not wanted to use maven or any similar frameworks) but the jax-rs "client" needed a dependency for org.glassfish.jersy.client, so i went out and read about dependencies in general and frameworks which i'm new to.
added maven framework to my project, and edited the pom.xml file for dependencies :
<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>groupId</groupId>
<artifactId>CVT Sale Data Manager</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.jersy.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersy.media</groupId>
<artifactId>jersy-media-moxy</artifactId>
</dependency>
</dependencies>
</project>
and this is part of the restapi code:
package api;
import javax.ws.rs.client.*;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
public class RestApi {
private static Client client;
private static WebTarget baseTarget; //base url
public RestApi()
{
//changed on the server
ClientBuilder.newBuilder().build();
client = ClientBuilder.newClient();
baseTarget = client.target("http://127.0.0.1:8000/api");
client = ClientBuilder.newClient();
}
somehow i'm still getting the same error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
at api.RestApi.<init>(RestApi.java:27)
at Launcher.initSingeltons(Launcher.java:36)
at Launcher.main(Launcher.java:29)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
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)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:87)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:185)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:70)
... 14 more
Exception running application Launcher
I'm very new to these dependencies type of thing so its very much possible that i have a very obvious error that i do not know about, i apologize in advance if that is the case.
I'm trying to use POM for a web page I'm trying to automate and I got the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I'm not sure what's going on. I added TestNG as well as any jar files to Selenium. Anyway, here's the code:
The first one is from a file I named Forumloginapplication.java in a package known as testcases
package testcases;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import objectrepository.SimpleProgrammerForum;
public class Forumloginapplication {
#Test
public void Login() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Adam\\Downloads\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://simpleprogrammer.com/members/");
SimpleProgrammerForum sp=new SimpleProgrammerForum(driver);
sp.Loginnav().click();
sp.Userid().sendKeys("10asmock");
sp.Userpass().sendKeys("secret");
sp.Rememberme().click();
sp.Login_button().click();
}
}
This one is named SimpleProgrammerForum.java in a package known as objectrepository:
package objectrepository;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class SimpleProgrammerForum {
WebDriver driver;
public SimpleProgrammerForum(WebDriver driver) {
this.driver = driver;
}
By login_navbar=By.xpath("//span[#class='p-navgroup-linkText'][contains(text(),'Log in')]");
By username=By.name("login");
By password=By.name("password");
By login_checkbox=By.name("remember");
By login_button=By.className("button-text");
public WebElement Loginnav() {
return driver.findElement(login_navbar);
}
public WebElement Userid() {
return driver.findElement(username);
}
public WebElement Userpass() {
return driver.findElement(password);
}
public WebElement Rememberme() {
return driver.findElement(login_checkbox);
}
public WebElement Login_button() {
return driver.findElement(login_button);
}
}
Another thing I get when I run the program is a popup which tells me: "Error: A JNI error has occurred, please check your installation and try again." followed by another popup which states: "A Java Exception has occurred."
TestNG has a JCommander dependency:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<name>testng</name>
<description>A testing framework for the JVM</description>
<url>http://testng.org</url>
...
<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.72</version>
</dependency>
...
</dependencies>
</project>
You will need to use Maven or add all TestNG dependencies manually as jar files.
I use Windows10 Pro 32bit ENG, EclipseEE Mars, Java 8_66. If I want create a easy bean project with Spring and run it it show me a error in Windows dialog. When I enter this dialog it generated exception.
Java Virtual Machine Launcher - Error :
A JNI error has occurred, please check your installation and try it again.
I have in CLASSPATH : Apache *.jars
•commons-logging-1.2.jar
•commons-logging-1.2-javadoc.jar
Spring *.jars
•spring-aop-4.1.5.RELEASE.jar
•spring-beans-4.1.5.RELEASE.jar
•spring-context-4.1.5.RELEASE.jar
•spring-aspects-4.1.5.RELEASE.jar
•spring-context-support-4.1.5.RELEASE.jar
•spring-core-4.1.5.RELEASE.jar
•spring-web-4.1.5.RELEASE.jar
•spring-webmvc-4.1.5.RELEASE.jar
•spring-expression-4.1.5.RELEASE.jar
I have the tested Java 8_60 vs Spring 4.1.5, Java 8_66 vs Spring 4.1.5 or 4.2.2.
KlientMetaTest.java
package klient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import server.ServerVypis;
public class KlientMetaTest {
public static void main(String[] args) {
#SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/Beans.xml");
ServerVypis obj = (ServerVypis) context.getBean("mujSpring"); // id beanu
obj.getMessage();
}
}
ServerVypis.java
package server;
public class ServerVypis {
private String message;
public void setMessage(String message){
this.message = message; }
public void getMessage(){
System.out.println("Zde je tvuj Spring vypis : " + message); }
}
beans.xml which is in /META-INF/ folder
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="mujSpring" class="server.ServerVypis">
<property name="message" value="Vypis z \META-INF\Bean.xml"/>
</bean>
</beans>
Exception which was showing in console :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
I have faced the same problem.
I made some changes in my pom.xml. Ff you are using the dependency of javax mail as well aws sdk then make sure that javax mail should be declare before the aws sdk's.
If you change the sequence then it will show the above error as it's loading jars in wrong sequence.As this worked in mine case, Hope this will work for you!
Problem solved. After I install Windows10, it broke my access to folders when I have save the external jars of frameworks.
Entry in my porm.xml for slf4j
enter code here
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
</dependency>
score code:
package test.test1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
//System.out.println( "Hello World!" );
Logger logger = LoggerFactory.getLogger("App.class");
logger.info("Test");
}
}
Compiling is successful through Maven, but during Running Exception is thrown.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFacto
ry at test.test1.App.main(App.java:14)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
Should set the classpath manually for slf4j jar file??
Maven picks up the dependencies you defined in the pom.xml from your local repository so everything compiles fine. However when you launch the application from a script or commandline you need to specify where the necessary classes are found, through the classpath.
For eclipse, there's the m2e & m2e-wtp plugins which integrate maven with your IDE so you don't need to add the jars manually one by one. Instead you'll have a sort of "virtual maven library" which contains references to all your dependencies, like in the image below:
I have a very simple HelloWorld code in Java which works ok. I'm using Eclipse and trying to figure out how to import dependencies for a project with the maven2 eclipse plugin.
public class testMavenDep {
public static void main(String arg[]){
System.out.println("Hello World");
}
}
However, when I right click on the project > configure > convert to maven project, and then try and run it gives me an error message saying...
Could not find the main class: testMavenDep.testMavenDep. Program will exit.
And the following in the console...
java.lang.NoClassDefFoundError: testMavenDep/testMavenDep
Caused by: java.lang.ClassNotFoundException: testMavenDep.testMavenDep
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main"
My pom file is...
<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>testMavenDep</groupId>
<artifactId>testMavenDep</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
My question is, for an already existing Java Project, what is the proper way to add maven dependencies? I can add the dependencies using the above method but I'm getting issues with it losing track of the main class. Thanks in advance!
What is the source folder that you are putting your main class in? By default, Eclipse puts it in src, but maven conventions are src/main/java. It could be that adding maven dependencies is changing your source folders so that your class is not compiled.