in Education by
I want to load and execute external jar file using URLClassLoader. What is the easiest way to get "Main-Class" from it? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I know this is an old question but, at least with the JDK 1.7, the previously proposed solutions did not seem to work. For this reason I am posting mine: JarFile j = new JarFile(new File("jarfile.jar")); String mainClassName = j.getManifest().getMainAttributes().getValue("Main-Class"); The reason why the other solutions did not work for me was because j.getManifest().getEntries() turns out to not contain the Main-Class attribute, that was instead contained in the list returned by the getMainAttributes() method.

Related questions

0 votes
    I want to load and execute external jar file using URLClassLoader. What is the easiest way to get "Main ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I want to load and execute external jar file using URLClassLoader. What is the easiest way to get "Main ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    Which of the following is correct error when loading JAR file with duplicate name? (a) java.io.NullPointerException ( ... JDBC of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    A file extension is separated from the main file name with a(n)- (a) question mark (b) exclamation mark (c) ... (e) None of above Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    I am trying to do some validation on the file name before it's saved. Here are my three file- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Which class loader loads jar files from JDK directory? (a) Bootstrap (b) Extension (c) System (d) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    I have a json file contains a icons object like this: "icons" : { "logo" : "fa fa-caret-down ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Can someone please tell me how to import a jar file in eclipse IDE? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    If I issue the find command as follows: find . -name *.ear It prints out: ./dir1/dir2/earFile1. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 26, 2022 in Education by JackTerrance
0 votes
    Which jar provides FileUtils which contains methods for file operations? (a) file (b) apache commons (c) ... Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    v. Which software will you use to make a .jar file? (A) Antivirus (B) MySQL (C) MS Word (D) Net Beans Select the correct answer from above options...
asked Dec 25, 2021 in Education by JackTerrance
0 votes
0 votes
    What is used to get class name in reflection? (a) getClass().getName() (b) getClass().getFields() (c) getClass( ... , JSP & API of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    What is used to get class name in reflection? (a) getClass().getName() (b) getClass().getFields( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
...