I just did fresh install of Eclipse & JBoss Tools but can't get the EL autocomplete to work. I tracked it down to the use of Jakarta API. If I use the older JavaEE API, the EL autocomplete works as expected, but nothing is displayed when using the Jakarta API in the pom.
Eclipse Version 2022-12 (4.26.0) using vm: JDK 17.0.4.1
JBoss Tools Version 4.26.0 Final (Installed from Marketplace)
Example using Jakarta
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope>
</dependency>
.
package test;
import java.io.Serializable;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
#Named
#ViewScoped
public class JakartaNamedObject implements Serializable {
private static final long serialVersionUID = 1L;
//getters and setter
}
Example using Javax
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
.
package test;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
#Named
#ViewScoped
public class JavaxNamedObject implements Serializable {
private static final long serialVersionUID = 1L;
//getters and setter
}
I used the Eclipse installer to install Eclipse 2022-12, with a brand new workspace and then Eclipse Marketplace to install JBoss Tools 4.26.
I guess the question is does EL autocomplete work with Jakarta and if so why is it not working in my fresh new setup?
Related
I am learning to hibernate so I made a small app for crud operation using mySQL as database. However, I am getting some errors and I cannot find the solution anywhere. SDK 17.0.2, I am not using maven , Also all hibernate final jar files have been added
my class:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.luv2code.hibernate.demo.entity.Student;
public class CreateStudentDemo {
public static void main(String[] args) {
// Create session factory
SessionFactory factory= new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
//Create session
Session session = factory.getCurrentSession();
try {
//Create a Student object
System.out.println("Creating new student");
Student tempStudent = new Student("Pau;", "Wall", "paul#luv2code.com");
//Start a transaction
session.beginTransaction();
//save the student object
session.save(tempStudent);
//commit transaction
session.getTransaction().commit();
}
finally {
factory.close();
}
}
}
runtime error :
java.security.PrivilegedActionException: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
Caused by: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "com.sun.xml.bind.v2.runtime.reflect.opt.Injector.defineClass" is null
java removed java.xml.bind from JAVA 9 and higher editions.
You need to add these jar files manually to your library
basically you can to that in this way.
If you use Intellij this is the easyest way:
jaxb-impl-2.3.0.jar
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
jaxb-core-2.3.0.jar
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
jaxb-api-2.3.1.jar
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
javax.activation-api-1.2.0.jar
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>javax.activation</artifactId>
<version>1.2.0</version>
</dependency>
If you use intellij here is a step my step to get these files through IDE
go to project structure:
Libraries, and click + sign
Chick to from Maven:
Paste these dependencies to the search.
It will automatically find exact jar files to download, Kist Paste it and click to the enter that is it.
Also later you can just add these files to the classpath just in case:
java removed java.xml.bind from JAVA 9 and higher editions.
Here is the eclipse solution:
In Eclipse IDE:
Download these jar files and paste them inside lib folder:
Go the project properties: The last line
Done these steps:
Happy Coding! :)
I have deleted the earlier version of eclipse I was using also updated the selenium 3.0.1, also added all the .jar files but now I'm getting a new error.
"The import org cannot be resolved"
Below is the code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class findByLinkedText {
public static void main(String[] args) {
System.setProperty("Webdriver.gecho.driver",
"C:\\Users\\lsharma1\\Desktop\\Selenium Drivers\\Gecho
driver\\ gechodriver.exe ");
WebDriver driver = new FirefoxDriver();
drive.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); String URL = "https://www.google.co.in/"; driver.get(URL); driver.close();
}
}
use this maven dependency in your pom :
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.3.1</version>
</dependency>
It is not recognizing this org package.
Hope that helps you.
May be the problem is that your selenium dependency has not been downloaded in your users/usename/.m2 folder.
I use this dependency in my project:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
and with this dependency tho mongoDB diver artefacts are in my project:
mongodb-driver-3.4.1.jar and
mongodb-driver.core-3.4.1.jar
both do have a package com.mongodb.
I get the following exception:
nested exception is java.lang.NoSuchMethodError: com.mongodb.DBRef.<init>(Lcom/mongodb/DB;Ljava/lang/String;Ljava/lang/Object;)V
Does anyone know what I'm doing wrong?
This is my collection:
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
#Document(collection = "MyCollection")
public class MyCollection {
#Id
private String id;
#DBRef
private User user;
}
Both legacy driver(2.x) and new driver(3.x) have same package (com.mongodb)
java.lang.NoSuchMethodError: com.mongodb.DBRef.<init>(Lcom/mongodb/DB;Ljava/lang/String;Ljava/lang/Object;)V
https://github.com/mongodb/mongo-java-driver/blob/2.14.x/src/main/com/mongodb/DBRef.java#L67
Notice the first argument is DB which is constructor in 2.x driver and is removed from 3.x version.
So it looks like your project is still referencing 2.x driver version.
Based on the advice to use JSF, the following sample would like to be run in order to learn more about JSF and to implement this technique into the servlet. However, a number of libraries is unable to be imported:
package tobedefinedservlet;
import javax.faces.bean.ManagedBean;
#ManagedBean
public class Hello {
final String world = "Hello World!";
public String getworld() {
return world;
}
}
javax.faces
The import javax.faces cannot be resolved
ManagedBean
ManagedBean cannot be resolved to a type
You have to include a JSF library like for example Mojarra in the classpath of your application.
First of all have a look at the Primefaces user guide (especially chapter 2.2). You can download e.g. Mojarra here and include the JAR or add the dependency to your POM.xml if you are using Maven. Hope that helps.
If you're using maven for build automation, add the latest jsf-api dependency to your pom.xml:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
Or the latest javax.faces-api implementation:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.3</version>
</dependency>
However, note that JSF is integrated into most Java EE application servers, such as JBoss.
See also this answer.
in my case ...I went to project properties and in the search engine I wrote facets ... I went to the right of the window and selected the runtime tab and select wildfly ... then apply and apply and close and solve ...
If you're not using maven you have to manually install the jar. You can download it at this link:
javax.faces
If you're using eclipse you can right click your Web App project and click properties at the bottom. Then under the java build path make sure the libraries panel at the top is selected then select the Web App library and on the right click Add External JARS. You can go to your downloads folder and select the jsf-api-2.1.jar and refresh the project and you can now import that annotation.
I have a GWT multi-module Maven project.
Layout:
pom.xml
client-module //client side: contains some base classes. I use JDK's java.util.log so that it logs on Firebug's console
server-module //server side: extends some code from client-module (so it uses JUL) for common behaviour. I use log4j
client-module is shared code.
I want to use SLF4J globally but it seems that I cannot use multiple bindings (multiple bindings per project, single binding per maven module).
I would agree, but I want to use a specific SLF4J binding per maven module.
So in my case would be SLF4J-JDK for client-module and SLF4J-log4j for server-module.
Pieces of relevant code:
pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.3</version>
</dependency>
client-module/BaseFoo.java
public abstract class BaseFoo {
private static final Logger logger = LoggerFactory.getLogger(BaseFoo.class.getName());
// ... interesting stuff
}
server-module/Foo.java
public class Foo extends BaseFoo {
private static final Logger logger = LoggerFactory.getLogger(BaseFoo.class.getName());
// ...more interesting stuff
}
I have already tried to configure according to documentation, but it doesn't work.
The problem is that SLF4J needs to be GWT ready.
The error I get:
[ERROR] Line 23: No source code is available for type org.slf4j.Logger; did you forget to inherit a required module?
What it means that GWT compiles the BaseFoo class to Javascript (that's why is it in client-module to run on client side) but fails because the classes/source code in SLF4j are not emulated.
Do you have any workarounds?
Thanks!