Ich meinte, wie du innerhalb des Projects auf die Resourcen zugreifst, da gibt’s doch bestimmt irgendwo ein Class#getResource oä?
Achso, das macht twitter4j library für mich ich greife da nicht per eigenen Code drauf zu.
Mein Quellcode sieht folgendermaßen aus:
[CODE lang="java" title="source"]package de.javafxbuch.tweetalot;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import twitter4j.*;
/**
* JavaFX App
*/
public class App extends Application {
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
Label label = new Label();
root.getChildren().add(label);
try{
Twitter twitter = TwitterFactory.getSingleton();
ResponseList<Status> homeTimeline = twitter.getHomeTimeline();
label.setText(homeTimeline.get(0).getText());
}
catch (TwitterException ex){
//
}
stage.setScene(new Scene(root));
stage.setTitle("Tweetalot");
stage.show();
}
public static void main(String[] args) {
launch();
}
}[/CODE]
Der Ausgegebene Fehlercode im Projekt wo die twitter4j.properties scheinbar nicht geladen wird sieht folgendermaßen aus:
[CODE lang="java" title="Debug"]"C:\Program Files\Java\jdk-16\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\lib\idea_rt.jar=53204:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\bin" -Dfile.encoding=UTF-8 -p C:\Users\Marius\IdeaProjects\tweetalot\target\classes;C:\Users\Marius\.m2\repository\org\openjfx\javafx-controls\13\javafx-controls-13.jar;C:\Users\Marius\.m2\repository\org\openjfx\javafx-controls\13\javafx-controls-13-win.jar;C:\Users\Marius\.m2\repository\org\openjfx\javafx-graphics\13\javafx-graphics-13.jar;C:\Users\Marius\.m2\repository\org\openjfx\javafx-graphics\13\javafx-graphics-13-win.jar;C:\Users\Marius\.m2\repository\org\openjfx\javafx-base\13\javafx-base-13.jar;C:\Users\Marius\.m2\repository\org\openjfx\javafx-base\13\javafx-base-13-win.jar;C:\Users\Marius\.m2\repository\org\twitter4j\twitter4j-core\4.0.7\twitter4j-core-4.0.7.jar -m de.javafxbuch.tweetalot/de.javafxbuch.tweetalot.App
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for details. See and register at http://apps.twitter.com/
at org.twitter4j.core@4.0.7/twitter4j.TwitterBaseImpl.ensureAuthorizationEnabled(TwitterBaseImpl.java:219)
at org.twitter4j.core@4.0.7/twitter4j.TwitterImpl.get(TwitterImpl.java:2082)
at org.twitter4j.core@4.0.7/twitter4j.TwitterImpl.getHomeTimeline(TwitterImpl.java:126)
at de.javafxbuch.tweetalot/de.javafxbuch.tweetalot.App.start(App.java:22)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Exception running application de.javafxbuch.tweetalot.App
Process finished with exit code 1
[/CODE]
Und hier noch die POM.XML aus dem Project wo die resource nicht geladen wird (Dem per Archetype erstellten Projekt):
[CODE lang="java" title="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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.javafxbuch</groupId>
<artifactId>tweetalot</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[3.0,)</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>de.javafxbuch.tweetalot.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>[/CODE]
Und hier noch die .iml aus dem Projekt falls es hilft.
[CODE lang="java" title="tweetalot.iml"]<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:13" level="project" />
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:win:13" level="project" />
<orderEntry type="library" name="Maven: org.twitter4j:twitter4j-core:4.0.7" level="project" />
</component>
</module>[/CODE]