Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:40:16+00:00 2026-05-25T01:40:16+00:00

I have a jar file, which I dynamically load during execution of my java

  • 0

I have a jar file, which I dynamically load during execution of my java file (say my.java).
I do it this way:

File newFile = new File("path");

JarFile newJar= new JarFile(newFile);

Now there is a particular java file inside this jar, which I know the name of (say known.class).
I want create an object of this known.class, and call a method inside it from my.java.

I am not sure how to go about this. Can any one help?
I tried looking online, but didn’t find anything helpful.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:40:17+00:00Added an answer on May 25, 2026 at 1:40 am

    You need a .class file (compiled java code) inside the jar, not a .java file. If you have this, add the .jar to your classpath, or to one of the directories in your classpath, and then you can simply reference the Object from your Java code.

    Ie:

    MyObject newObj = new MyObject();
    

    Here’s how your specify the jar in the classpath:

    java -classpath ".;myjar.jar" org.mine.MyClass
    

    Edit: Since you don’t want to change the classpath, try something like this:

    File file  = new File("/path/to/myjar.jar");
    URL url = file.toURL();  
    URL[] urls = new URL[]{url};
    ClassLoader cl = new URLClassLoader(urls);
    
    Class cls = cl.loadClass("org.mine.myclass")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which reads all the files from a directory. File textFolder
I have jar file which is signed on my local machine. Its working fine
I have a jar file which is used in html file as applet. I
I have a .jar file which is 1MB. Without debug info, it should be
I have a .jar file which has a command line interface. I want to
I have an existing jar file which I run. It is the Selenium RC
I have a jar file and I want to know which all classes are
I have a .jar file that i've placed in my D:\Coldfusion8\wwwroot\web-inf\lib\ directory. The file
I have a jar file that has a file named client.ts in (when viewing
I have a JAR file named helloworld.jar . In order to run it, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.