I added a library to my JavaFX projects following these steps:
- File --> Project Structure --> Project Settings --> Libraries --> + --> Maven
- Insert the Maven coordinates and checked the "Download to projectPath/libs"
- In pom.xml added the correct dependecy declaration
- In module-info.java added the 'requires module'
Importing the library to my class seems to work, but after calling a method from the library, it results in a
Caused by: java.lang.ClassNotFoundException: org.web3j.utils.Numeric at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168) Now, i initially thought was a library problem, but reproducing the same steps in a normal Maven project (and trying to run the same exact code snippet) works perfectly.
Any ideas why this could happen? Am i doing something wrong in importing the library?
HELLOAPPLICATION.JAVA
public class HelloApplication extends Application { @Override public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); Scene scene = new Scene(fxmlLoader.load() , 320 , 240); stage.setTitle("Hello!"); stage.setScene(scene); stage.show(); Web3j web3j = Web3j.build(new HttpService("http://127.0.0.1:8545")); web3j.ethGetBlockByNumber(DefaultBlockParameter.valueOf(new BigInteger("14000000")), true); } public static void main(String[] args) { launch(); } }
Edit:
POM.XML
<?xml version="1.0" encoding="UTF-8"?> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>1.0-SNAPSHOT</version> <name>demo</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <junit.version>5.8.1</junit.version> </properties> <dependencies> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>17.0.1</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>17.0.1</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.web3j</groupId> <artifactId>web3j-evm</artifactId> <version>4.9.0</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>17</source> <target>17</target> </configuration> </plugin> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.8</version> <executions> <execution> <!-- Default configuration for running with: mvn clean javafx:run --> <id>default-cli</id> <configuration> <mainClass>com.example.demo/com.example.demo.HelloApplication</mainClass> <launcher>app</launcher> <jlinkZipName>app</jlinkZipName> <jlinkImageName>app</jlinkImageName> <noManPages>true</noManPages> <stripDebug>true</stripDebug> <noHeaderFiles>true</noHeaderFiles> </configuration> </execution> </executions> </plugin> </plugins> </build> MODULE-INFO.JAVA
module com.example.demo { requires javafx.controls; requires javafx.fxml; requires core; opens com.example.demo to javafx.fxml; exports com.example.demo;}
mvn packageshould also work...