Jdivert java.lang.ClassNotFoundException error when ran - java

Trying to use this library, but whenever I run it. It gives me the following. I updated my pom file and thought it would be the solution, but I still receive an error.
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Pointer
at org.example.Main.main(Main.java:11)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Pointer
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
Here is my code
public class Main {
public static void main(String[] args) throws WinDivertException {
System.out.println("Hello world!");
WinDivert w = new WinDivert("tcp.DstPort == 80 and tcp.PayloadLength > 0");
w.open(); // packets will be captured from now on
Packet packet = w.recv(); // read a single packet
System.out.println(packet);
w.send(packet); // re-inject the packet into the network stack
w.close(); // stop capturing packets
}
}
And here is my pom.xml file
<?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>org.example</groupId>
<artifactId>Glacial1.1</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.ffalcinelli</groupId>
<artifactId>jdivert</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Tried updating my pom file and it didn't work

Related

How can I solve "org.slf4j.impl.StaticLoggerBinder" error to run my Javalin web app?

I am using IntelliJ IDE where I created a maven project to build a website. I am trying to use Javalin as it is a lightweight framework to use. As per the documentation of Javalin, my pom.xml files is:
<?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>org.example</groupId>
<artifactId>Web-App</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.13.6</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
</project>
And under src/main/java, I created a HelloWorld.java to run my webapp. The code is:
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7000);
app.get("/", ctx -> ctx.result("Hello World"));
}
}
When I run, I get a error like this:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/NoWhenBranchMatchedException
at io.javalin.core.JavalinConfig$Inner.<init>(JavalinConfig.java:73)
at io.javalin.core.JavalinConfig.<init>(JavalinConfig.java:63)
at io.javalin.Javalin.<init>(Javalin.java:52)
at io.javalin.Javalin.create(Javalin.java:88)
at io.javalin.Javalin.create(Javalin.java:76)
at HelloWorld.main(HelloWorld.java:5)
Caused by: java.lang.ClassNotFoundException: kotlin.NoWhenBranchMatchedException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 6 more
Under this circumstances. what could have been my error behind this?
Thanks in advance.
You are missing a logging implementation. I recommend you use this "javalin-bundle" dependency:
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin-bundle</artifactId>
<version>3.13.6</version>
</dependency>
It includes some extra libraries, including logging libraries, which are missing if you only use <artifactId>javalin</artifactId>.
(You also get Jackson, which is used by Javalin behind the scenes to handle JSON rsources - for example ctx.json(obj).)
You don't have to use the bundle - you can provide your own logging implementation.

Run a jar file from unix command line

I have created a jar file from mvn command but when i am trying to run it i am getting below error :
java -cp target/new-repl.jar package.repl
Error: Could not find or load main class package.repl
Caused by: java.lang.ClassNotFoundException: package.repl
I got many links on stack overflow but none of them helped me. Could you please help me to run this from command line. Below is the my .java file:
package repl;
public class Test {
public static void main(String[] args) throws IOException {
....
}
}
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>repl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>repl</name>
<description>build tar for repl</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<finalName>new-repl</finalName>
<directory>target</directory>
</build>
</project>
You can do like this. Type fully qualified class name instead of typing package name
java -cp target/new-repl.jar repl.Test
The error says it all
Error: Could not find or load main class package.repl
your class name is not package.repl, it is repl.Test

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication.Tried all the solution but still not

Console Error
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.ayush.JavaApi.main(JavaApi.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
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
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ayush</groupId>
<artifactId>JavaCourse</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
JavaClass with Main Method
package com.ayush;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class JavaApi {
public static void main(String[] args) {
SpringApplication.run(JavaApi.class,args);
}
}
I am running this program as java application but it is giving me error. i have try all the solution and also provided in the stackoverflow which is updating the maven but it is not working and still giving me the error.
thanks for the help in advance.
I've copied all your files to Intellij but it had no issue with your file.
Maybe hierarchical structure of your project (class JavaApi should be in JavaCourse package) or IDE setting (clean/rebuild, reimport pom) is wrong.
For beginning with Spring boot. You can generate project from https://start.spring.io/
I deleted the Project and created it again .It worked for me .Thanks everyone for the help

sparkjava and eclipse unresolved compilation problems:

I have followed the tut here http://sparkjava.com/documentation.html#getting-started
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spark</groupId>
<artifactId>Spark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spark</name>
<description>spark</description>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</project>
Hello.java
import static spark.Spark.*;
public class Hello {
public static void main(String[] args) {
get("/hello", (req, res)-> "Hello World");//eclipse error this line
}
}
I got an error with eclipse
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
req cannot be resolved to a variable
Syntax error on token ",", . expected
Syntax error on token "-", -- expected
at Hello.main(Hello.java:5)
Java's lambda expressions are a feature in Java 8: Oracle link. You'll need to change your compliance level (and java version, and pom) to java 8 to make this example compile.

Jboss7 + neo4j + hibernate-ogm = StoreLockException?

I'm trying to setup neo4j under JBoss7 using hibernate=ogm, heres my pon.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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Think01</groupId>
<artifactId>CityMiners</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>RESTfulDemoApplication Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-neo4j</artifactId>
<version>4.1.3.Final</version>
</dependency>
</dependencies>
<build>
<finalName>CityMiners</finalName>
</build>
</project>
here's my persistance.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/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_1_0.xsd" version="1.0">
<persistence-unit name="ogm-neo4j" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="hibernate.ogm.neo4j.database_path" value="d:/dev/q7"/>
<property name="hibernate.ogm.datastore.provider" value="neo4j_embedded"/>
<property name="hibernate.search.default.directory_provider" value="ram" />
</properties>
</persistence-unit>
</persistence>
here's my singleton bean:
#Singleton
#Startup
public class Test {
private EntityManagerFactory emf;
#PostConstruct
public void init() {
emf = Persistence.createEntityManagerFactory("ogm-neo4j");
}
#PreDestroy
public void kill() {
emf.close();
}
}
and heres what I receive after deploy:
[2015-06-06 11:04:14,734] Artifact CityMiners:war: java.lang.Exception: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"CityMiners.war\".component.Test.START" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"CityMiners.war\".component.Test.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
Caused by: javax.ejb.EJBException: javax.persistence.PersistenceException: Unable to build entity manager factory
Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory
Caused by: org.hibernate.service.spi.ServiceException: OGM000071: Unable to start datatore provider
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, d:\\dev\\q7
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter#c5c0fa' was successfully initialized, but failed to start. Please see attached cause exception.
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: d:\\dev\\q7\\store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
Caused by: java.io.IOException: Couldn't lock lock file d:\\dev\\q7\\lock because another process already holds the lock."}}
the stack trace says "Couldn't lock lock file d:\dev\q7\lock because another process already holds the lock." but I'm pretty sure no external process even touches that file ( I do not run another neo4j proces in parallel ) - it looks like somehow JBoss itself holds that lock...
do you know how to come over this?
Thanks in advance!

Categories

Resources