Eclipse Eclipse mit Maven mit Abhängigkeiten

julianpe

Aktives Mitglied
Hallo,

ich bin noch recht neu in der Java Programmierung und wollte mal ein paar externe Bibliotheken/Abhängikeiten für ein Testprogramm nutzen.

Ich bin aus privatem Interesse auf diese Bibliothek aufmerksam geworden:
http://financequotes-api.com/

Ich habe aus meinem Projekt in Eclipse ein Maven Projekt gemacht und folgende Abhängigkeit in die pom.xml Datei eingefügt:

Code:
<dependency>
    <groupId>com.yahoofinance-api</groupId>
    <artifactId>YahooFinanceAPI</artifactId>
    <version>x.y.z</version>
</dependency>

Das ganze sieht in der pom.xml nun so aus:

Code:
<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>StockViewer</groupId>
  <artifactId>StockViewer</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencyManagement>
      <dependencies>
<dependency>
    <groupId>com.yahoofinance-api</groupId>
    <artifactId>YahooFinanceAPI</artifactId>
    <version>x.y.z</version>
</dependency>
      </dependencies>
  </dependencyManagement>
</project>


Mein Quelltext sieht mit dem Beispielcode aus dem Projekt nun so aus:
Code:
import java.math.BigDecimal;
import yahoofinance.*;

public class MainPage {

    public static void main(String[] args) {
        Stock stock = YahooFinance.get("INTC");
         
        BigDecimal price = stock.getQuote().getPrice();
        BigDecimal change = stock.getQuote().getChangeInPercent();
        BigDecimal peg = stock.getStats().getPeg();
        BigDecimal dividend = stock.getDividend().getAnnualYieldPercent();
         
        stock.print();

    }

}
Wie kann ich nun die .jar Dateien aus der Bibliothek in mein Projekt mit einbinden, bzw was muss ich genau im Quelltext über import noch einfügen?
 

julianpe

Aktives Mitglied
Ich habe die .jar Dateien in das Projekt importiert (rechte Maustaste auf das Projekt -> Import -> General -> Archive File). Ist das soweit korrekt? Ich habe auch im Quelltext die Zeile import yahoofinance.*; selber eingefügt. Ist das richtig so?

//Edit:

In der Zeile Stock stock = YahooFinance.get("INTC");
Wird ein neuer Datentyp stock vom Typ Stock angelegt. Dieser wird Werte von YahooFinance.get() zugewiesen. Diese Zuweisung wird bei mir im Eclipse unterkringelt. Wahrscheinlich kann er keinen Bezug darauf nehmen?!
 

Anhänge

  • Auswahl_009.png
    Auswahl_009.png
    95,6 KB · Aufrufe: 47
Zuletzt bearbeitet:

MWin123

Bekanntes Mitglied
Habe es gerade bei mir in IntelliJ IDEA ausprobiert.

<version>x.y.z</version> ist wahrscheinlich ein Platzhalter, probier mal <version>1.4.0</version>

Sonst musst du eigentlich nichts machen, bei mir wurde als ich "Stock" eingetippt habe, der Import vorgeschlagen.

Java:
import yahoofinance.Stock;
import yahoofinance.YahooFinance;

public class Main {
    public static void main(String[] args) {
        Stock stock = YahooFinance.get("INTC");
        System.out.println(stock);
    }
}
 

julianpe

Aktives Mitglied
Danke für Deine Antwort.
Ich befürchte, dass ich bei Eclipse die Importierung der .jar Dateien irgendwie falsch vorgenommen habe.
Ich bekomme, nachdem ich die Versionsnummer auf 2.0.0 geändert habe, immernoch folgende Fehlermeldung:
Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Stock cannot be resolved to a type
    YahooFinance cannot be resolved

    at gui.MainPage.main(MainPage.java:11)
In Zeile 11 steht: Stock stock = YahooFinance.get("INTC");

//Edit:
Fehler gefunden. Habe die Dateien falsch eingebunden.
Man muss über Projektproperties als externe Libarys die .jars einbinden.

Besten Dank für Deine Hilfe :)
 
Zuletzt bearbeitet:

MWin123

Bekanntes Mitglied
Erstell mal ein neues Projekt und probier es dort nochmal.
Normal musst du nur die pom.xml anpassen und auf importieren drücken.
Also nichts von Hand zuweisen.
 

FawKes100

Aktives Mitglied
Moin, habe ein ähnliches Problem - Ich bin momentan dabei einer Tutorialreihe zu Folgen, die einen Discord-Bot programmiert. Der Autor des Tutorials verwendet dabei allerdings IntelliJ IDEA, wobei ich bisher immer Eclipse benutzt hatte und daher dabei bleiben wollte. Im ersten Teil ist es nötig eine JDA zu importieren, das ist mir auch problemlos gelungen, da ich eine externe JAR Datei der Bibliothek vorliegen hatte.

Nun ist es im nächsten Schritt allerdings erforderlich eine externe Bibliothek Namens Lava-Player einzubinden:
https://github.com/sedmelluq/lavaplayer
Allerdings gibt es hier nirgends eine Jar, die ich so dem BuildPath zuweisen könnte..

Wie kann ich nun diese Bibliothek importieren? Auf der Seite ist eine Anleitung zu finden, was in die pom.xml geschrieben werden muss, allerdings hilft mir das nicht sehr viel weiter.

Habe das Projekt zu einem Maven-Projekt konvertiert und habe in die pom.xml den Code der auf der Seite zu finden ist eingetragen über Notepad++, wobei ich x.y.z bei der Version durch 1.2.56 ersetzt habe.
Dann hab ich Eclipse einmal neu gestartet um die pom.xml zu refreshen, aber die externe Bibliothek wurde nicht herunter geladen.
Kann mir da wer helfen? Glaube dass das ein typischer Anfängerfehler ist..
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
Robertop Maven Warnung "'version' contains an expression but should be a constant" in Eclipse verstecken IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
K Maven + GWT (+ Eclipse)? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
L Eclipse Eclipse - Projekte "mischen" Dynamisches Web Projekt + Maven IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
thet1983 Eclipse Eclipse - Maven - Wildfly - archetype:generate IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
G eclipse und Webprojekte mit Maven IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
D Eclipse Eclipse deployment assmebly + Maven IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
P Eclipse Maven Support IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
I Maven, Eclipse, building workspace loop IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
S Eclipse Java + Shellscript mit Maven und Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 11
M Eclipse Maven/Eclipse ClassLoader Reihenfolge IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
Gregorrr Eclipse Best Practice: Multi-Projekt mit Eclipse + EGit (Git) + m2e (Maven) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
J Eclipse Checkout/Import Maven Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
C Eclipse Verständnisfrage Eclipse+Maven+Resources IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
C Eclipse Verständnisfrage Eclipse+Maven+Dependencies IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
F Maven plugin für Eclipse: tld dependencies in jars IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
R Eclipse beim Ausführen zur Eingabe in die Konsole springen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
T Eclipse Java Projekt funktioniert in Eclipse, aber nach export kein Dateizugriff IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
M Eclipse oder IntelliJ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
JonasM Gibt es eine Libary in Eclipse mit der ich Daten per USB an einen Microkontroller Senden kann? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
N Erstellen einer ausführbaren jar Datei in Eclipse (Linux Mint) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 17
O Eclipse stürzt beim Autovervollständigen ab IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 17
C In Eclipse Einrückung im Java-Editor einstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
Avalon html ist nicht html in eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
A Docker im Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
Robertop Eclipse resolved Target-Platform nicht wegen automatischem HTTPS IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
C Eclipse englisch, deutsche Kommentare leider rot unterkringelt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
T Eclipse von Java 1.8 auf 17 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
S [Eclipse] Zwei verschiedene Konfigurationen erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
A Eclipse Projekt-Umzug mit Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
D Eclipse Eclipse und OpenGL IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
M Ausführbares Programm aus Eclipse exportieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
Java00User00 Eclipse Theme IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
F Eclipse für Java 1.8 ARM einrichten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
D Crawler funktioniert in intellij aber in Eclipse nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
U Problem mit Eclipse - WindowBuilder - memoryLeak? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 15
F Eclipse - Änderung am Code ohne Applikation Neustart IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
E Hilfe mit Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
B Eclipse version control System das ohne Internet funktioniert/nur lokal auf Computer? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
B Eclipse Problem mit jar Datei? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
N Eclipse erzeugt plötzlich keine (default package) mehr IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 24
F alle Eclipse Projekte auf git hochladen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
O Java Eclipse Umlaute werden nicht richtig dargestellt in Konsole IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
B .exe Datei für Eclipse Java Programm erstellen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
Eclipse Build path duplication entry IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 11
B Wie nicht-java Datei mit Eclipse benutzen (Excel Datei einlesen)? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 16
T GlassFish mit Eclipse, Dynamic Web Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
nbergmann Eclipse Eclipse-Concole: Ergebnis-Zahlenfolge erscheint kurz und verschwindet dann wieder IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 21
berserkerdq2 Eclipse Eclipse führt nicht dei Klasse aus, bei der ich bin, muss das immer manuell ändern, was tun? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
MiHimbert Eclipse + Wildfly26 + primefaces11 + openjdk18 IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 22
S Eclipse Umlaute IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
S Fehlermeldung bei Nutzung Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
LimDul IDEA IntelliJ Tipps für den Umstieg von Eclipse auf intelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J Eclipse - kein Server verfügbar zum ausführen meines Java Projektes IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
P PHP Skript wird nicht mit highlights markiert(Eclipse) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
B Eclipse Autovervollständigung zeigt nicht alle Methoden einer Klasse an IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
P Eclipse- Zip Datei als Prgramm IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
T Eclipse scheint awt Libary nicht zu besitzen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
G eclipse mit neuestem JDK einrichten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
P Cucumber Plugin Installation . Eclipse Warnmeldung IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
J Eclipse CDT Library einbinden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
J Javac File generieren Eclipse oder IntellJ (JNI) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
sham5 Eclipse-Remote-Debugging von Java mit mehreren Prozessen oder Ports oder Netzen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
Eichi1979 Eclipse Fehler in Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
Arita wie kann man die automatische erstellte Ordner von Eclipse in D Drive ziehen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
nonickatall paho.client.mqttv3 in Eclipse installieren/einbinden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
A Einbindung von FXML-Dateien in Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
A JavaFX in Eclipse einbinden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 22
nonickatall Remote Debugging Eclipse/Raspberry IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
H Outline Fenster (Gliederung) wird mit deutschem Sprachpaket nicht angezeigt, Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
M Kann EGit nicht auf Eclipse installieren? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
Tobero Eclipse Eclipse zeigt mir alles als Warnung an IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
B Versionen kontrollieren / dokumentieren mit Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
keinLebenNurCode Eclipse Eclipse: Gelbes Hilfsfenster für Funktionen und Methoden anzeigen lassen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
windl Probleme mit Eclipse unter Linux IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
H Eclipse Fehler beim starten des Projekts IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
B Kompilieren in Eclipse ( 2 Klasse ohne main()-Methode) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
N Eclipse debug Gradle-Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
R Eclipse-Fehler IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
M Eclipse - Fehlermeldung bei JavaFX-Projekt "java.lang.module.FindException: Module javafx.controls not found" IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 23
P ERROR: org.eclipse.equinox.p2.engine code=0 session context was:(profile=C__Users_birgit_eclipse_java-2020-124_eclipse, phase=org.eclipse.equinox.inte IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
H eclipse Fehler: Hauptklasse konnte nicht gefunden - bei Umwandlung in git IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
H Eclipse - Refactoring - mehrere Pakete geleichzeitig verschieben IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
T Eclipse, Console gibt Fragezeichen zurück. IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
N Eclipse aus Java-Application JavaFX machenModule javafx.controls not found IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
K Eclipse Einstellung "kaputt" IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
G Java Eclipse IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
M Einzelne Java-Dateien mit Eclipse compilieren - Wie geht das? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
Robertop Eclipse Eclipse Startprobleme "Java was started but returned exit code=1" IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
Splayfer Problem mit der Eclipse Autovervollständigung... IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
ruutaiokwu Eclipse inkonsistent?? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
T Eclipse - Keine Vorschläge außerhalb main-Methode IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
S Java8 Eclipse Nutzer will auf Java14 wechseln IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
H kann in Eclipse org.junit nicht importieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
C Eclipse Plugin ClassLoader IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
T Eclipse: Projekt aus meinem Workspace als Library auswählen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
ruutaiokwu Eclipse Eclipse-Plugin für UML "Reverse Engineering", um aus Code Klassendiagramme zu erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
OSchriever Eclipse: JavaFX mit JDK11 nutzen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
S Wie importiere ich am besten grosse Projekte in Eclipse am Beispiel von Apache ANT IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
U Eclipse und Tab Order IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
OSchriever Eclipse Eclipse - Automatischer import von Klassen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1

Ähnliche Java Themen

Neue Themen


Oben