Daniel.V :
I want to execute specific method inside class in jar file which is don't have main method, with java command I tried java -cp classes.jar com.example.test.Application
but I get this error Error: Could not find or load main class
After decompile jar file I have found Application class inside it is there any way to call a static function inside Application class in a jar file?
i.bondarenko :
You could use Jshell:
$ jshell --class-path ~/.m2/repository/org/apache/commons/commons-lang3/3.9/commons-lang3-3.9.jar
| Welcome to JShell -- Version 11.0.4
| For an introduction type: /help intro
jshell> org.apache.commons.lang3.StringUtils.join("a", "b", "c")
$1 ==> "abc"
Or create a java class with main compile it and run with java:
Test.java:
class Test {
public static void main(String[] args) {
String result = org.apache.commons.lang3.StringUtils.join("a", "b", "c");
System.out.println(result);
}
}
Compile and run:
$ javac -cp /path/to/jar/commons-lang3-3.9.jar Test.java
$ java -cp /path/to/jar/commons-lang3-3.9.jar:. Test
abc
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=321855&siteId=1