简体   繁体   中英

How to compile a Java file with dependencies in a Windows command prompt window?

I am using a jar file that is dependent to a GitHub source file, available here: Java Stream Player (Library) . The jar file is named musicplayer-1.0.0.jar . The jar file has the following manifest ( MANIFEST.MF ):

Manifest-Version: 1.0
Created-By: Maven Jar Plugin 3.2.0
Build-Jdk-Spec: 17
Class-Path: lib/slf4j-api-1.7.31.jar lib/logback-classic-1.2.3.jar lib/l
 ogback-core-1.2.3.jar lib/java-stream-player-10.0.0.jar lib/mp3spi-1.9.
 5.4.jar lib/jlayer-1.0.1.4.jar lib/junit-3.8.2.jar lib/jflac-codec-1.5.
 2.jar lib/vorbis-support-1.1.0.jar lib/tritonus-all-0.3.7.2.jar lib/jor
 bis-0.0.17-2.jar lib/jaudiotagger-2.2.7.jar lib/commons-io-2.6.jar
Implementation-Title: musicplayer
Implementation-Version: 1.0.0
Main-Class: gr.hua.dit.oop2.musicplayer.MusicPlayerApp

The build file is the following in Maven :

<repositories>
    <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
    </repository>
</repositories>

And the dependency is defined with:

    <dependency>
        <groupId>com.github.goxr3plus</groupId>
        <artifactId>java-stream-player</artifactId>
        <version>Tag</version>
    </dependency>

How can I compile my code in cmd with simple commands without using Maven (or any other tool)?

The commands I use are:

javac -classpath musicplayer-1.0.0.jar Jukebox.java
java Jukebox Vivaldi-Storm.mp3

musicplayer-1.0.0.jar is the jar file that uses the GitHub source code, Jukebox.java is my java file and Vivaldi-Storm.mp3 is an argument needed by my class.

The second command results in the error exception:

java.lang.ClassNotFoundException: com.goxr3plus.streamplayer.stream.StreamPlayerListener

I can't use a simple import leading to the external source code like:

import com.goxr3plus.streamplayer.stream.*;

When you execute your JukeBox using the second command, you need to use the -classpath option, too. However, when executing java you need to specify musicplayer-1.0.0.jar and all its dependencies in the classpath value. Eg you need to download the goxr3plus java-stream-player and add that to your classpath as well. Then you need to do that for all the other dependencies of musicplayer as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM