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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:13:22+00:00 2026-06-07T15:13:22+00:00

I tried a java program which needs a jar file in another path in

  • 0

I tried a java program which needs a jar file in another path in a unix server.
i want this jar to be used when ever i need the program as i use a servelet to call this program.
When i compile the program including jar like java -cp .;*.jar myProgram , it works.
But when i call the below function from a servlet , the jar is not getting inclued and so get error.
please advise.
Its the same when i try from my eclipse project where i had the jar included.

void doBless(int i,String Envs) {
    String url = "jdbc:sybase:Tds:ramu-sys:5000/".concat(Envs);
    connection b=new connection();
    System.out.println(url);
    String queryString;
    String temp;
    try {
      Class.forName("com.sybase.jdbcx.SybDriver");
    }
    catch( Exception e ) {
      System.out.println("Failed to load sybase driver.");
      return;
    }

    try {

      ResultSet myResultSet =null;

          Connection con = DriverManager.getConnection(url, "sa", "");
      Statement select = con.createStatement();

      temp="insert into Persons (P_Id,FirstName,LastName,Address,City) values (" +i+",'" + blessArray.get(i)+ "','"+ blessArray.get(i)+ "','"+ blessArray.get(i)+ "','"+ blessArray.get(i)+ "')";
      System.out.println(temp);

       select.executeQuery(temp); 

       select.close();
       con.close();


    }
    catch( Exception e ) {
      e.printStackTrace();
    }
}
  • 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-07T15:13:23+00:00Added an answer on June 7, 2026 at 3:13 pm

    I think there is a misunderstanding of some environment related concepts and its the reason of why you’re getting such an error.

    When you’re running a ‘usual’ java progam as you stated with ‘java -cp’ you by yourself explicitly define which jars should be in the classpath.
    This is not the case when you’re running the servlet. Servlets can’t by directly run by java (they don’t have method ‘main’ if you want).

    Instead they’re designed to be run inside another java based application (called container). In terms of deployment, you compile your servlet into a class file, put it into the special directory and run your container.

    Container application reads the files in the directory, recognizes the servlet and creates an instance of it. In other words, it manages the servlet for you.
    Now, in order to recognize the classes in runtime, containers use their custom class loaders, so you have to deploy your jars that the server relies on somehow that these classloaders will correctly load the classes from these jars.

    Suggested above tools like maven or ant – just handle the process of building your application and can ‘put’ your jar in a correct place, but IMO you should still understand what goes where and what are responsibilities of each component/tool.

    Ok, So, what are these places where the jar should be stored.
    There is more than one such a place, and you should understand what are the consequences of putting the jar in each place.
    The most easy solution is to wrap your servlet in WAR file (or even leave it as a directory in a predefined layout).
    WAR (Web Application Archive) is a file/directory with all the servlets and jars inside.
    Since all the web containers should understand the WAR’s layout, you can place your JAR in WEB-INF/lib folder inside your WAR file. I believe you should go for this option.

    Another option is to put the jar in a directory where the jars needed for the container itself reside. This is less preferable, but sometimes needed.

    I hope this makes things clearer 🙂 Good Luck!

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

Sidebar

Related Questions

I have a Java program which prints to a HTML file. Another method reads
I am using Eclipse to program in Java. I tried installing from this site
I'm writing a program which needs to traverse a set of directories. Tried to
I am trying to build a simple java program which creates a db file,
I'm using a .jar file which I imported to Eclipse, and when I used
I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,
I'm trying to run a java program from a jar file. Java can't find
I am writing a java program that needs a file open dialog. The file
I have a Java program which needs to be a startup program that runs
I'm writing this Java program in which I have a JFrame and a Thread.

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.