//Eclipse java code:
package openbrowser;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenChrome {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");
WebDriver driver=new ChromeDriver();
}
}
eclipse error
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Om Murugaa\Downloads\Testing\selenium-server-standalone-3.141.59.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.eclipse.jetty.http.Http1FieldPreEncoder not in module
Adding maven into eclipse resolved this error.
Related
I am trying to run the below code
package JavaBasics;
enter code here
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class OpenBrowserURL {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Pooja\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.makemytrip.com/?ccde=us");
}
}
I am getting error java.lang.NoClassDefFoundError for get as the jar files that i downloaded 3.141.59 has get as void
How can i fix this? Is this an issue with the jar files I downloaded. Please advice
I tried using TinyLog for a sample application to make sure understanding how it works, so that i can use it for my work application.
But, while using i get an exception to type cast the Writer (Compile time error). If i typecast it, it throws runtime error as below.
Code :
import java.io.FileWriter;
import java.io.IOException;
import org.pmw.tinylog.Configurator;
import org.pmw.tinylog.Logger;
import org.pmw.tinylog.writers.ConsoleWriter;
import org.pmw.tinylog.writers.Writer;
public class TestClass {
public static void main(String[] args) throws IOException {
Configurator.defaultConfig().writer(new ConsoleWriter()).addWriter((Writer) new FileWriter("data.txt")).activate();
Logger.info("welcome to tinylog logger.....");
}
}
Error :-
Exception in thread "main" java.lang.ClassCastException: java.io.FileWriter cannot be cast to org.pmw.tinylog.writers.Writer
at TestClass.main(TestClass.java:12)
Please help us :).
You can fix it easily. Just import org.pmw.tinylog.writers.FileWriter instead of java.io.FileWriter. The class java.io.FileWriter is the file writer of the JVM, but you need tinylog's file writer.
Afterwards you can remove the class cast "(Writer)" as org.pmw.tinylog.writers.FileWriter is an implementation of the interface org.pmw.tinylog.writers.Writer. However the class java.io.FileWriter does not implement the interface org.pmw.tinylog.writers.Writer. Therefor the reported ClassCastException has been thrown.
import org.pmw.tinylog.Configurator;
import org.pmw.tinylog.Logger;
import org.pmw.tinylog.writers.ConsoleWriter;
import org.pmw.tinylog.writers.FileWriter;
public class TestClass {
public static void main(String[] args) {
Configurator.defaultConfig().writer(new ConsoleWriter()).addWriter(new FileWriter("data.txt")).activate();
Logger.info("welcome to tinylog logger.....");
}
}
I'm creating a simple web application with a register form, and I have used Hibernate. But i have this kind of error:
this is the code:
AddUser.java
import java.io.IOException;
import javax.imageio.spi.ServiceRegistry;
import javax.security.auth.login.Configuration;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
#WebServlet("/CreateUser.do")
public class AddUser extends HttpServlet {
private static final long serialVersionUID = 1L;
public AddUser() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Configuration config = new Configuration().configure("hibernate.cfg.xml");
ServiceRegistry servReg = new StandardServiceRegistryBuilder().applySettings(config.getProperties()).build();
SessionFactory factory = config.buildSessionFactory(servReg);
Session session = factory.openSession();
session.beginTransaction();
User u = new User(request.getParameter("firstname"), request.getParameter("lastname"), request.getParameter("login"), request.getParameter("password"));
session.save(u);
session.getTransaction().commit();
session.close();
RequestDispatcher view = request.getRequestDispatcher("useradd.jsp");
view.forward(request, response);
}
}
This is the error: ERROR
How can I do to solve this problem? Thanks you!
#LuisMuñoz
I add also the error if someone want to see it directly.
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Servlet execution threw an exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.Error: Unresolved compilation problems:
Cannot instantiate the type Configuration
The method configure() is undefined for the type Configuration
The method getProperties() is undefined for the type Configuration
The method buildSessionFactory(ServiceRegistry) is undefined for the type Configuration
AddUser.doPost(AddUser.java:32)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
My Eclipse Page:
ECLIPSE
From the error it looks like there is no method configure for Configuration object. Check the javadocs https://docs.oracle.com/javase/9/docs/api/index.html?javax/security/auth/login/Configuration.html
I have followed exact instructions from the link eclipse-jcde, and now I have all JCDE features in my eclipse (I'm using eclipse ver 4.3.1). I made a new java card project and added new applet file to it, but when I try to run the project it shows below error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/String
and this is my (empty!) code:
package myPackage;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISOException;
public class MyApplet extends Applet {
private MyApplet() {
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new MyApplet().register();
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
}
what should I do?
Friends'm trying to connect my application in openshift through hibernate orm.
But the deployment is failing. You can check the error message in the server log:
2013/01/03 14:02:59,296 ERROR [com.wavetech_st.util.HibernateUtil] (MSC service thread 1-4) Falha na criação do objeto SessionFactory: org.hibernate.HibernateException: hibernate.cfg.xml not found
2013/01/03 14:02:59,298 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/testehome]] (MSC service thread 1-4) Exception starting filter conexaoFilter: java.lang.ExceptionInInitializerError
at com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:26) [classes:]
at com.wavetech_st.util.HibernateUtil.(HibernateUtil.java:12) [classes:]
at com.wavetech_st.web.filter.ConexaoHibernateFilter.init(ConexaoHibernateFilter.java:31) [classes:]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.10.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09-icedtea]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09-icedtea]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09-icedtea]
Caused by: org.hibernate.HibernateException: resources/hibernate.cfg.xml not found
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1943) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at org.hibernate.cfg.Configuration.configure(Configuration.java:1924) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
at com.wavetech_st.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19) [classes:]
... 11 more
I am creating this application in Eclipse. I have tested it on the local server JBoss 7.1 and it works. However when I try remote gives the error. I set the file hibernate.cfg the datasource before you deploy to OpenShift:
<property name="connection.datasource">java:jboss/datasources/MysqlDS</property>
This is my directory structure:
This is my WebFilter:
package com.wavetech_st.web.filter;
import java.io.IOException;
import javax.servlet.*;
import org.hibernate.SessionFactory;
import com.wavetech_st.util.HibernateUtil;
public class ConexaoHibernateFilter implements Filter {
private SessionFactory sf;
#Override
public void init(FilterConfig config) throws ServletException {// executado quando o aplicativo web e colocado no ar
this.sf = HibernateUtil.getSessionFactory();
}
#Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
try {
this.sf.getCurrentSession().beginTransaction();
chain.doFilter(servletRequest, servletResponse);
this.sf.getCurrentSession().getTransaction().commit();
this.sf.getCurrentSession().close();
} catch (Throwable ex) {
try {
if(this.sf.getCurrentSession().getTransaction().isActive())
this.sf.getCurrentSession().getTransaction().rollback();
} catch (Throwable t) {
t.printStackTrace();
}
throw new ServletException(ex);
}
}
#Override
public void destroy() {}
}
This is my HibernateUtil:
<pre>
package com.wavetech_st.util;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateUtil {
static final Logger logger = Logger.getLogger(HibernateUtil.class);
private static final SessionFactory sessionFactory = buildSessionFactory();
private static ServiceRegistry serviceRegistry;
private static SessionFactory buildSessionFactory() {
try {
Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
return cfg.buildSessionFactory(serviceRegistry);
} catch (Throwable e) {
logger.error("Falha na criação do objeto SessionFactory: " + e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Please, help :-/
I solved my problem by following the hint of these guys:
stackoverflow.com/questions/4934330/org-hibernate-hibernateexception-hibernate-cfg-xml-not-found
shaunabram.com/tag/hibernate/
My problem was to put the hibernate.cfg.xml file in the wrong location. How to use Maven I should not put in the root directory but in the src directory root resouces.
Thanks mate, I had the same problem in jBoss-Openshift and Mybatis but with your answer you help me, I attached a picture where I put Mybatis config file who is similar file as hibernate