i have problems with setting up JMS. I tried using Active MQ and OpenJMS but the same error occurs. Iam clueless on how to solve it:
When i execute this:
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;
public class Main {
public static void main(String[] args) throws NamingException {
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.exolab.jms.jndi.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://localhost:3035/");
Context context = new InitialContext(properties);
}
}
I get this error:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.exolab.jms.jndi.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.exolab.jms.jndi.InitialContextFactory]
After some googling i think the problem is that a jar is not in the right classpath, but all the answers already assume that i know which jar and where to store it, but this is not the case here.
Which Jar are they talking about? Where can i get it? Where do i need to store it?
Iam using IntelliJ btw. Could you point me in the right direction?
ActiveMQ is working (http://localhost:8161/ shows webpage of ActiveMQ)
Here are my steps on how i created the project:
File -> New Project -> Java -> SDK1.8 -> Next -> Next -> Project Name: Test -> Right click src folder -> New -> Java Class -> Name: Main -> Paste code from above -> Run -> Error
EDIT: for all the people having the same errors: OpenJMS comes with a libfolder. Install these libraries and it should work
Here is a good explanation on how to add external jars to your project in intellij, and regarding to
Which Jar are they talking about? Where can i get it?
here is a useful web site where you can search jar files using criterias as the name of a class or a package.
I think the jar you are needing is Openjms, here is a link to download it.
Related
I started a new JavaFX application with the JavaFX project template that IntelliJ gives you that will only display a GUI created with Scene Builder with some line charts, as far as I'm concerned, the code is right and simple, it's just a test project.
Also, I can't visualize the .class file in IntelliJ
The message is:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\pv3\Desktop\PruebasFX_OracleFXProyectInicio\target\classes
Caused by: java.lang.module.InvalidModuleDescriptorException: GraficasVentPrueba1.class found in top-level directory (unnamed package not allowed in module)
Process finished with exit code 1
My code:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class GraficasVentPrueba1 extends Application {
#Override
public void start(Stage stage) throws IOException{
FXMLLoader launcherGraficas = new FXMLLoader(GraficasVentPrueba1.class.getResource("GraficasVentPrueba1.fxml"));
Scene emergenteGraficas = new Scene(launcherGraficas.load());
stage.setScene(emergenteGraficas);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
It supposed to just open the .fxml. Instead it shows that error message
Java Platform Module System
In your error message, unnamed package not allowed in module is the key here.
Check your module-info.java file created by the JavaFX project template in IntelliJ. Be sure to edit that file to keep up with changes you make.
👉 I would guess that you changed the names of your classes and/or packages but did not edit your module-info.java file to suit.
Tip: When changing names of classes and packages in your app in IntelliJ, use IntelliJ’s Refactor features. When doing so, the module-info.java file should be automatically updated. See manual on Rename refactorings
When using JavaFX, you must learn about the Java Platform Module System. While optional for some other kinds of Java apps, compliance with Java modularity is required of JavaFX apps.
As commented, for working with JavaFX, you must understand both Java packages and Java modules. Resources include:
Packages (tutorial by Oracle)
Understanding Java 9 Modules, article by Paul Deitel.
A few books including The Java Module System by Nicolai Parlog.
I am working with TestContainers for my project but when I am running the test in eclipse, I am having the following error with me
On top of this window, it also gives a specific error which says Cannot find test class "DBInitTest" in project "myProject".
package org.ft.cdcp;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.junit.jupiter.Testcontainers;
#Testcontainers
public class DBInitTest {
private final PostgreSQLContainer sqlContainer = new PostgreSQLContainer(DockerImageName.parse("postgres:alpine"));
#BeforeEach
public void setUp() {
sqlContainer.start();
}
#Test
#DisplayName("Initializing database container")
public void initTest() {
assertTrue(sqlContainer.isRunning());
}
}
Do note that I have checked and rechecked the dependencies, everything is intact and there's no problem with them, something's buggy only about JUnit5.
I looked it up online but only found something which said that I should Right click on source folder --> Build Path --> Use as source path, but this fix doesn't seem to be working for me.
I am not expert and cannot explain why this fixed any but:-
Today I started having the same problem as you reported.
After fiddling about for a while (reinstalling STS, lombok ...) I eventually clicked on the error entry that popped up. It took me to "Edit lauch configuration properties" for the Test that would not run.
Once there I clicked on the "Search" on the line of the "Test Class:" field.
I selected the correct class from the "Test Selection" window that popped up.
(nb what I thought was the same value that was already there)
UPDATE
Now I feel silly.
I had a test class called "AdminTaskControllerMockMvcTest" in a file called "AdminTaskControllerMockMvcTests.java", ie class name with an "s" on the end.
Renaming my test class to "AdminTaskControllerMockMvcTests" fixed all my issue.
Regards, Andrew
So I figured out what the error was.
My project structure was like this:
└─main_project/
├─ myProject/
└─ other_sub_project/
It might sound stupid but it's definitely something beginners tend to often (as I did). I have opened the main_project in my IDE and there were other sub-projects inside that projects too. The DBInitTest was inside the sub-project named myProject.
I was getting the error because of this structure only. So when I closed the project and opened the sub-project directly from the IDE, the error was gone.
Steps to resolve:
Close the currently opened project i.e. main_project
Click on Open Project in your IDE
Navigate to the folder of the sub-project i.e. myProject and open it inside your IDE
Voila, the error is gone now. ;)
I don't know if this question has been asked/answered yet. If so, I'm sorry. But I'm new to IntelliJ and there's a lot of foreign words I yet need to understand.
My problem is as follows:
I installed the complete IntelliJ package, created a new Java project and created a new class inside my src folder:
package de.itsme.hello;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
So I try to run it and I get this Error:
Error: Could not find or load main class cucumber.api.cli.Main
Caused by: java.lang.ClassNotFoundException: cucumber.api.cli.Main
I tried adding cucumber-core:4.0.1 to the project's dependencies but then I got another exception:
Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
at cucumber.runtime.BackendModuleBackendSupplier.get(BackendModuleBackendSupplier.java:39)
at cucumber.runner.SingletonRunnerSupplier.createRunner(SingletonRunnerSupplier.java:38)
at cucumber.runner.SingletonRunnerSupplier.get(SingletonRunnerSupplier.java:32)
at cucumber.runtime.Runtime.run(Runtime.java:75)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:8)
I don't need cucumber or at least not for now. Is there a way to make it either work or remove it from the project?
Thanks in advance!
Maybe you have the packet JDK installed incorrectly and this produces you an error. Or maybe your classspath is incorrect.
I have started learning Java and encountered a problem when trying to run my first program as given below:
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world!");
}
}
On Eclipse Photon I encounter this error when running it:
Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)
I looked and there is my .class file in bin directory and my .java in the src directory.
Is that normal? How do I fix that?
I was getting the same error. Deleting the module-info.java file solved it for me.
It seems that you haven't created a package. My usual procedure in Eclipse is:
Create a new Java project
Inside that project: Create a new package
Inside that package: Create a new Java class
Eclipse will help you a lot with the settings. Then just copy your code into that class and hit the 'start' button.
by removing module class problem solved for me in eclipse
i moved my main class and sample.fxml file to a new package that throws this error below
"Error occurred during initialization of boot layer
java.lang.module.FindException: Error reading module: C:\Users\Thomas\eclipse-workspace\HelloWorld\bin
Caused by: java.lang.module.InvalidModuleDescriptorException: HelloWorld.class found in top-level directory (unnamed package not allowed in module)"
i moved my class file and fxml file to normal position. it fix my problem. but i have to find why it happends. cheers....
Executing the project from another workspace solved for me in Eclipse.
create a package and refactor your Main class in that package in your case its HelloWorld then it will run fine.
To understand how modules work in java please watch this spectacular video MODULES IN JAVA
I've solved it do according to this steps:
right click on your main project name
choose new>>package
in the opening window fill name field and then choose (radio button) "create pakage info"
then click ok and in package explorer drag your class under the new package which you created, then run it.
Delete module-info.java from your project and run ,it should work. Or Create package and then create class inside package.
I am trying to connect to a MongoDB database hosted on mlab using the Java driver on a servlet.
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
public class MongoConnection {
protected void connectToMongo(String loc){
String dbName = "readings";
String collection = "data";
MongoClientURI uri = new MongoClientURI("mongodb://user:pass#ds143109.mlab.com:43109/readings");
MongoClient client = new MongoClient(uri);
MongoDatabase db = client.getDatabase(dbName);
MongoCollection<Document> readings = db.getCollection(collection);
Document doc = Document.parse(loc);
readings.insertOne(doc);
client.close();
}
}
The problem is I am getting the following error:
java.lang.NoClassDefFoundError: com/mongodb/MongoClientURI
I looked at one answer (How to resolve ClassNotFoundException: com.mongodb.connection.BufferProvider?) that highlighted to me that I need other jars, I have since downloaded them however I am still getting this error.
I am using Eclipse and adding the three jars to the build path, navigating through the menu by right clicking on the project then following Build Path -> Configure build path -> Java build path -> libraries -> add external JARs.
Is this the right way to do it? Is there something else I am supposed to do as well/instead?
You have java.lang.NoClassDefFoundError - that means your class is missed during runtime (not during build/compile time). So you should open your "Run Configurations" dialog for the project (project context menu -> "Run As" -> "Run Configurations...") and make sure you have bson-xxx.jar, mongodb-driver-xxx.jar, and mongodb-driver-core-xxx.jar somehow listed in Classpath tab. And yes, like Xavier Bouclet said - if you run it under application server - this jars should be added to your server's classpath.
You have to make sure that the mongodb jars are exported to server if your call to the database are made from the servlet.
Check how you deploy your app on your local server dans make sure the jars are there.
I was facing similar issue with my Mule 4 project.
Failed to invoke lifecycle phase "initialise" on object:
That was pointing to:
java.lang.NoClassDefFoundError: com/mongodb/MongoClientURI
So I had to updated POM file in plugin section (mule-mave-plug, idk what would it be in java project):
<sharedLibraries>
<sharedLibrary>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-legacy</artifactId>
</sharedLibrary>
</sharedLibraries>