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 7940855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:29:42+00:00 2026-06-03T23:29:42+00:00

I have a java class and I want to Load a class inside a

  • 0

I have a java class and I want to Load a class inside a external jar.

The jar is xstream-1.4.2.jar the class is com.thoughtworks.xstream.XStream

I search in google but I cant insert an external reference to my project (jar)

this is my code:

File file  = new File("c:\\cubrid\\bin\\xstream-1.4.2.jar");
URL url = file.toURL();  
URL[] urls = new URL[]{url};
ClassLoader cl = new URLClassLoader(urls);
Class cls = cl.loadClass("com.thoughtworks.xstream.XStream");
cadena = cls.toXML(objeto);

I dont know how to call a method, I read some documents in google but sorry is my second day programming on Java.

I want to generate a .class library. This is loaded for another application. for this I need to use some method to load the jar externally.

this class file will be loaded as java stored procedure in a CUBRID Database server.

my problem is error: java.lang.reflect.InvocationTargetException

my code

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.xml.parsers.DocumentBuilderFactory;

public class jp2 {

    static ResultSet resultado = null;
    static String cadena = null;
    static Statement statement = null;
    static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   

public static String Validar(String tblUsuariosLogin,String tblUsuariosPassword)
{


    try {
        Class.forName("cubrid.jdbc.driver.CUBRIDDriver");
        Connection con = DriverManager.getConnection("jdbc:default:connection:"); 


            File file  = new File("c:\\cubrid\\bin\\xstream-1.4.2.jar");
            URL url = file.toURL();  
            URL[] urls = new URL[]{url};
            ClassLoader cl = new URLClassLoader(urls);

            Class cls = cl.loadClass("com.thoughtworks.xstream.XStream");

               // XStream xstream = new XStream();
                cadena = cls.toXML(objeto); 


            return cadena;

        } catch (Exception e) {
            // TODO: handle exception
        }
        return cadena;


    }



}

CUBRID database allow you load .class files and use it at stored procedures.

  • 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-06-03T23:29:43+00:00Added an answer on June 3, 2026 at 11:29 pm

    Take a look at URLClassLoader, it allows you to load classes from an external JAR file.

    /edit
    Your problem is that you are trying to call a method on the Class of an object, not the object itself. If you want to call the method, you need to create a new instance (see the second method provided) of that Class, and call the method on the result.

    Are you sure you don’t just want to have that JAR file on your classpath and deal with the classes directly instead of using reflection to load and instantiate the classes as you need them?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have immutable Java objects like this (strongly simplified): class Immutable {
I'm using Java. I want to have a setter method of one class that
I have a jar file, which I dynamically load during execution of my java
I have a jar with main-class which can be executed like: java -jar test.jar
I have a java class and I need to debug it (put breakpoints and
I have a java class containing all the columns of a database table as
I have a Java class MyPojo that I am interested in deserializing from JSON.
I have a Java class, Node as follows : class Node { public ArrayList<Node>
I have a Java class which handles both single valued and multi-valued data. Therefore,
If I have a java class which is package-private (declared with class, not public

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.