LWJGL: Could not initialize class org.lwjgl.glfw.GLFW$Functions - lwjgl

Trying out LWJGL and trying to make the demo run: https://www.lwjgl.org/guide. The Java code is simply copy-pasted from the site.
I'm using Ivy within Eclipse to fetch the libraries:
<ivy-module version="1.0" xmlns:extra="http://ant.apache.org/ivy/extra">
<info organisation="foo" module="bar"/>
<dependencies>
<dependency org="org.lwjgl" name="lwjgl" rev="3.1.0"/>
<dependency org="org.lwjgl" name="lwjgl-glfw" rev="3.1.0"/>
<dependency org="org.lwjgl" name="lwjgl-opengl" rev="3.1.0"/>
<dependency org="org.lwjgl" name="lwjgl-opengles" rev="3.1.0"/>
<dependency org="org.lwjgl" name="lwjgl-bgfx" rev="3.1.0"/>
<dependency org="org.lwjgl" name="lwjgl-platform" rev="3.0.0">
<artifact name="lwjgl-platform" type="jar" extra:classifier="natives-linux"/>
<artifact name="lwjgl-platform" type="jar" extra:classifier="natives-osx"/>
<artifact name="lwjgl-platform" type="jar" extra:classifier="natives-windows"/>
</dependency>
</dependencies>
</ivy-module>
On running the HelloWorld application I receive the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.glfw.GLFW$Functions
at org.lwjgl.glfw.GLFW.glfwTerminate(GLFW.java:717)
at HelloWorld.run(HelloWorld.java:54)
at HelloWorld.main(HelloWorld.java:132)
My Eclipse setup:
Not sure what I am missing here.
Thanks for any help.

Related

Jersey with jersey-media-json-jackson leads to stacktrace

I am about to do my first steps with REST, Jersey, Maven, Eclipse, Tomcat.
The first step - making tomcat to answer with a text - worked smooth after a few fixes about Tomcat 10 and Java 17.
Now I am switching to JSON and got a problem:
I do not get the expected answer (the same as the text) but a stacktrace with the root cause
java.lang.NoSuchMethodError: 'void org.glassfish.jersey.model.internal.CommonConfig.<init>(jakarta.ws.rs.RuntimeType, java.util.function.Predicate)'
I looked at org.glassfish.jersey.model.internal.CommonConfig and there is no <init> function, just a <clinit>. But afai could find, no class exposes an <init> funtion.
What may have caused my problem?
The program:
package net.codejava;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("/bonjour")
public class HelloResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
public String direBonjour() {
return "{\"name\":\"greeting\", \"message\":\"Bonjour tout le monde!\"}"; }
}
The pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.codejava</groupId>
<artifactId>HelloREST</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>HelloREST</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warName>HelloREST</warName>
<outputDirectory>/opt/tomcat/webapps/</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
The response:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Servlet.init() for servlet [Jersey REST Service] threw exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
jakarta.servlet.ServletException: Servlet.init() for servlet [Jersey REST Service] threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.base/java.lang.Thread.run(Thread.java:833)
Root Cause
java.lang.NoSuchMethodError: 'void org.glassfish.jersey.model.internal.CommonConfig.<init>(jakarta.ws.rs.RuntimeType, java.util.function.Predicate)'
org.glassfish.jersey.server.ResourceConfig$State.<init>(ResourceConfig.java:97)
org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:335)
org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:498)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:275)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:338)
jakarta.servlet.GenericServlet.init(GenericServlet.java:158)
jakarta.servlet.http.HttpServlet.init(HttpServlet.java:140)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:400)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1734)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.base/java.lang.Thread.run(Thread.java:833)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/10.1.4

log4j2 exception handling not working

I am using log4j2 with this 2 dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.6.2</version>
</dependency>
When I try to log for example an error with a throwable like:
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.annotations.Test;
public class Test {
private static final Logger logger = LogManager.getLogger(Test.class);
#Test
public void testSendMessage() throws Exception {
Exception exception = new Exception("some exception");
logger.error("error with exception", exception);
}
}
using patternlayout:
<Configuration>
<properties>
<property name="filters">org.testng,org.apache.maven,sun.reflect,java.lang.reflect</property>
</properties>
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" direct="true">
<PatternLayout pattern="%maxLen{%d{DEFAULT} [%p] %c{-3}:%L - %enc{%m} %xEx{filters(${filters})}%n}{200}"/>
</Console>
</Appenders>
<Loggers>
<logger name="my.test.class.path" level="trace" additivity="false">
<AppenderRef ref="ConsoleAppender" />
</logger>
</Loggers>
</Configuration>
Then the filtered packages won't disappear from the stacktrace, I can't even manipulate the stacktrace in any way like maximizing the lines:
%xEx{5}
Highlightning also don't work in eclipse nor in Kibana(ELK environment).
Can anybody help?
Could it be that the %xEx PatternLayout converter doesn't support property substitution in its options?
What if you put the packages you want to filter directly in the filters list?
It may be worth raising a Jira ticket on the Log4j 2 issue tracker for this.
try to remove the ending{200}. i think there is an issue using more sub parameters.
here is a snippet which works. please note if you add additional things like separator(|) it will stop working [tested in version 2.8.1 and 2.9.1]
<Properties>
<Property name="exfilters">org.jboss,java.lang.reflect,sun.reflect</Property>
<Property name="log-pattern">%d %-5p %m%n%xEx{filters(${exfilters})}/Property>
</Properties>
...
<PatternLayout pattern="${sys:log-pattern}"/>
Works for me on Log4j2 v 2.17 (and also for rThrowable):
<Properties>
<Property name="PACKAGE_FILTER">org.jboss,java.lang.reflect,sun.reflect</Property>
<Property name="LOG_PATTERN">%xThrowable{filters(${PACKAGE_FILTER})}</Property>
</Properties>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
</Appenders>

Errors by binding MySQL to JBoss 7.0

I'm trying to use MySQL with JBoss 7.0. I've changed the standalone.xml and added the driver and the dataresources inside of it, i've also added the module.xml file in the modules/com/mysql/main folder.
This is a part of standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
</connection-url>
<driver>
h2
</driver>
<pool>
<prefill>
false
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
FailingConnectionOnly
</flush-strategy>
</pool>
<security>
<user-name>
sa
</user-name>
<password>
sa
</password>
</security>
</datasource>
<datasource jndi-name="java:/mydb" pool-name="my_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:mysql://localhost:3306/mydb
</connection-url>
<driver>
mysql
</driver>
<security>
<user-name>
root
</user-name>
<password>
</password>
</security>
<statement>
<prepared-statement-cache-size>
100
</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>
org.h2.jdbcx.JdbcDataSource
</xa-datasource-class>
</driver>
<driver name="mysql" module="com.mysql">
<driver-class>
com.mysql.jdbc.Driver
</driver-class>
<xa-datasource-class>
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
and the module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.39-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And when i deploy (using eclipse) i get this error:
14:36:28,108 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
14:36:28,109 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
14:36:28,110 WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) Unable to instantiate driver class "com.mysql.fabric.jdbc.FabricMySQLDriver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.web-adwords-project_war is already registered
14:36:28,132 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 11.2)
14:36:28,133 WARN [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) Unable to instantiate driver class "oracle.jdbc.OracleDriver": org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.web-adwords-project_war is already registered
can anyone help me ?

Hibernate, JPA, No Persistence provider for EntityManager named

I'm working on a Swing application with JPA and Hibernate. But every time I try to call following code to get EntityManager
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
EntityManagerFactory emf = Persistence.createEntityManagerFactory("abcd");
EntityManager em = emf.createEntityManager();
I get following exceptions:
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named abcd: Provider named org.hibernate.jpa.HibernatePersistenceProvider threw unexpected exception at create EntityManagerFactory:
javax.persistence.PersistenceException
javax.persistence.PersistenceException: Unable to build entity manager factory
and
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
Path to persistence.xml is my.jar/meta-inf/persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="abcd" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.connection.url" value="xxx"/>
<property name="hibernate.connection.password" value="xxx"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.user" value="xxx"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
Dependencies:
All dependencies except junit are in a classpath
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
<scope>compile</scope>
</dependency>
It seems, it cannot find your persistence.xml file. The correct folder for the persistence.xml file is META-INF and not meta-inf.

PUT operations to URL failed with status code 405: Method Not Allowed : Ivy Remote publishing

I am getting the following error while try to publish artifact into the remote repository.
BUILD FAILED
/home/kannan/.jenkins/workspace/projectA/build.xml:87: impossible to publish artifacts for com.mycompany#projectA;1.0: java.io.IOException: PUT operation to URL http://myserver.com/repository/com.mycompany/projectA/1.0/ivy-1.0.xml failed with status code 405: Method Not Allowed
at org.apache.ivy.util.url.AbstractURLHandler.validatePutStatusCode(AbstractURLHandler.java:82)
at org.apache.ivy.util.url.BasicURLHandler.upload(BasicURLHandler.java:264)
at org.apache.ivy.util.url.URLHandlerDispatcher.upload(URLHandlerDispatcher.java:82)
at org.apache.ivy.util.FileUtil.copy(FileUtil.java:150)
at org.apache.ivy.plugins.repository.url.URLRepository.put(URLRepository.java:84)
at org.apache.ivy.plugins.repository.AbstractRepository.put(AbstractRepository.java:130)
at org.apache.ivy.plugins.resolver.RepositoryResolver.put(RepositoryResolver.java:234)
at org.apache.ivy.plugins.resolver.RepositoryResolver.publish(RepositoryResolver.java:216)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:275)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:254)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:166)
at org.apache.ivy.Ivy.publish(Ivy.java:615)
at org.apache.ivy.ant.IvyPublish.doExecute(IvyPublish.java:312)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:277)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
impossible to publish artifacts;
PUT operation to URL http://myserver.com/repository/com.mycompany/projectA/1.0/ivy-1.0.xml failed with status code 405: Method Not Allowed
ivy.xml
<ivy-module version="2.0">
<info organisation="com.mycompany" module="projectA" revision="${version}">
<description>
This project provides interface to projectA.
</description>
</info>
<publications>
<artifact />
</publications>
<dependencies defaultconfmapping="*->*,!sources,!javadoc">
<dependency org="com.hazelcast" name="hazelcast-client" rev="2.5" transitive="false"/>
<dependency org="com.hazelcast" name="hazelcast" rev="3.1.5" transitive="false"/>
<dependency org="log4j" name="log4j" rev="1.2.16" transitive="false"/>
</dependencies>
</ivy-module>
ivysettings.xml
<ivysettings>
<settings defaultResolver="defaultresolver" />
<property name="ibiblio-maven2-root" value="http://repo1.maven.org/maven2/" />
<property name="build-server" value="http://myserver.com/repository" />
<resolvers>
<chain name="defaultresolver">
<ibiblio name="local" m2compatible="true" root="${build-server}" />
<url name="repository">
<ivy pattern="${build-server}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="${build-server}/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>
build.xml
<ivy:publish artifactspattern="${build.dir}/[artifact].[ext]"
resolver="repository" organisation="com.mycompany"
module="projectA" pubrevision="${version}" status="release" conf="java" />
I had the same error message trying to publish to Artifactory. It turned out I forgot to include the port 8081 in the URL.
what is your HTTP Server? Did you use Something like Artifactory?
If you are using Apache, the PUT operation is disabled by default (maybe the same for most Web servers). You'll have to enable it and associate a backend script to handle the query as expected (retrieving artifacts from query and saving them on file system).
I enable it using PHP, you can see how from my GitHub repository: https://github.com/opatry/ivy-frontend
if you are using Artifactory as your repository, check this out:
http://www.jfrog.com/confluence/display/RTF2X/Working+with+Ivy
The ivy settings should change the build-server property
<ivysettings>
<settings defaultResolver="defaultresolver" />
<property name="ibiblio-maven2-root" value="http://repo1.maven.org/maven2/" />
<property name="build-server" value="http://myserver.com/repository/libs-snapshot-local/" />
<resolvers>
<chain name="defaultresolver">
<ibiblio name="local" m2compatible="true" root="${build-server}" />
<url name="repository">
<ivy pattern="${build-server}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="${build-server}/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>