Hi, in the application basics section in the DevOps prerequisite, there is a question in “LABS – JAVA – BUILD & PACKAGING” that I didn’t understand well after reading the hint and rewatching the video.
“What is the output for the main app when you run /opt/maven/my-app/target/my-app-1.0-SNAPSHOT.jar created with maven package?”
Can you provide a link to the lab please?
I’ve found the lab:
Labs - Java - Build & Packaging - KodeKloud
It is the last question. So it is asking for the output when you run the app. It is not ambiguous.
Well, you’re right it is not ambiguous, I just didn’t know how to answer it, and after I saw the hint java -cp /opt/maven/my-app/target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
on host01
I become more confused.
-cp is not mentioned in the course, so I had to read the Java man page but I still didn’t get what this option meant and also why -jar wouldn’t work in this case
I hope you can clarify, thanks in advance
-cp /opt/maven/my-app/target/my-app-1.0-SNAPSHOT.jar
: specifies the classpath. It tells the JVM to look for class files inside the /opt/maven/my-app/target/my-app-1.0-SNAPSHOT.jar
JAR file.
com.mycompany.app.App
: is the name of the class containing the main
method to execute. The JVM will look for this class in the locations specified by the classpath.
-jar
wouldn’t work in this context, the JVM expects the JAR file to have a manifest file with a Main-Class
attribute specifying the class with the main
method to execute.