How to call method in jar file with terminal?

霸气de小男生 提交于 2019-12-17 20:45:31

问题


I have a compiled project in a jar file and I need to call a method from it.How can I do that in ubuntu terminal?


回答1:


You can not call any method from terminal or cmd of any class.

You can execute class through terminal.

If your jar is executable try: java -jar "Name of your Jar"

Or set the class path of your jar: java -classpath path-to-jar <package>.<classname>




回答2:


java -cp path/to/jar <package>.<classname>

example:

java -cp test.jar org.dekz.HelloWorld



回答3:


I need to call a method from it.

This is not very specific statement. if you are interested to call main method of your Main class then you can do

java -jar path/to/yourjar/yourJar.jar
  • JAR Basics

if you want to call a method from this class from another class then you need to add this jar into your classpath and then you can access other methods. but since you wrote from terminal I assume the first approach fits for you




回答4:


you can call a specific method from a jar file if and only if the developer programmed the file to call it from outside. You can use a jar explorer to fine the details of each class inside a jar file



来源:https://stackoverflow.com/questions/7950538/how-to-call-method-in-jar-file-with-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!