Need to set classpath if i jar my classes???

as above?
Do i need to set?
why sometimes even though i never set my classpath, my application still runs?
Thanks

Your JAR file must be in the classpath.
Setting the class path
http://java.sun.com/j2se/1.4/docs/tooldocs/win32/classpath.html
Jesper

Similar Messages

  • Setting classpath to execute jar file.

    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
          ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
            at utility.tpc.generate.Tpc.generate(Unknown Source)
            at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
             utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?

    baskark wrote:
    I have dependency jar files to execute my jar file.
    set classpath=./lib/tpc.jar;./lib/jxl.jar;
    ./lib/log4j-1.2.15.jar;./lib/logSys.jar;
    java -jar ./lib/tpc.jar %1java -jar seems not taking classpath environment variables and showing error as
    Exception in thread "main" java.lang.NoClassDefFoundError:
    com/sys/logger/LogManager
    at utility.tpc.generate.Tpc.generate(Unknown Source)
    at utility.tpc.generate.Tpc.main(Unknown Source)The below one works, but I dont want to give all jar files along with java command and to make complicate.
    java -cp "./lib/tpc.jar;./lib/jxl.jar;./lib/log4j-1.2.15.jar;./lib/logSys.jar;"
    utility.tpc.generate.Tpc %1Is there a way to make first one to work ? Will adding "Class-Path:jxl.jar,log4j-1.2.15.jar,logSys.jar" in my manifest file make it work ?The jar command is specified to work as you have shown. That is, when you use "java -jar..." the system or command line classpath is ignored. The only classpath that can be used with "java -jar..." is the Class-Path in the manifest. You need to separate the different paths using space characters, not ; or : and the paths need to be relative to the jar file. (I am not sure if "./" will work and it is not needed to specify relative to the jar file.)
    Edited by: atmguy on Dec 14, 2009 8:42 AM

  • Help Please: Do I need to set Classpath?

    Hi friends,
    I installed JDK 1.4 on Windows, do I need to set up classpath after installation? How to do it?
    What if I install JDK on Linux? How to set the classpath?
    This puzzles me a lot, any response will be greatly appreiated!
    THANKS!!!

    Windows: probably not, but if you do it depends on the version of Windows. http://forum.java.sun.com/thread.jsp?forum=54&thread=246067

  • Setting Classpath so one jar can access another jar

    I am having trouble with running an application as a jar that accesses other custom libraries.
    I have made a small example to try to get this working.
    I have
         HelloWorld.class - that prints out "HelloWorld" and then throws a custom exception JWIException
         JWIException - exception that is in a package com.jeffersonwells.util
    I have put the JWIException class in the directory D:\apps\jbin\com\jeffersonwells\util.
    I have a manifest file that looks like the following.
         Manifest-Version: 1.0
         Main-Class: HelloWorld
         Class-Path: "d:\apps\jbin\"
    I have created a jar with the manifest file and the HelloWorld class
    When I run the jar, I get the following
         Exception in thread "main" java.lang.NoClassDefFoundError: com/jeffersonwells/util/JWIException
    So, I believe the classpath is not being set correctly.
    Then the second part would be to get the HelloWorld app to access the JWIException in another jar file instead of in the directory structure. I assume if the first scenario gets working, this will be fixed as well.
    I would greatly appreciate any assistance you can provide.
    Thanks,
    Tom Krueger

    I thank you all very much. The problem I was having was with not having relative paths in my Class-Path.
    Having the relative paths will work for the most part, however, sometimes we may want to move the executable jar to a different location. Does anyone have a great solution taking the following into consideration.
    Previous posts have said you can reference classpaths through http or ftp. Great, however if you set this to your http://domain/whatever I'm assuming this will prohibit you from moving the application from dev to test to production without modifying the url.
    Thanks for any thoughts!!
    P.S.
    I'm also in a battle here whether to jar libraries or not. jaring allows you to easily move them from server to server and more importantly for me determine versions of compatible files. However, the argument against jaring is speed of development, why jar if I can pull up a java file compile it and copy it to the server. Why waste time in the whole jaring process.
    Thanks again!!!

  • Setting classpath to ojdbc.jar on UNIX

    I�m trying to connect to an Oracle database using the ojdbc.jar
    Class.forName("oracle.jdbc.driver.OracleDriver");
    How do I set the classpath on Unix to look inside the .jar file? I know it�s the correct driver because I�ve pulled the oracle/jdbc/driver/* folder from the jar file.

    How do I set the classpath on Unix to look inside the .jar file?http://www.google.com/search?hl=en&q=how+to+set+a+classpath+in+unix

  • Set CLASSPATH  in Oracle

    I HAVE CREATED THE JAVA PROGRAM TO READ FROM EXCEL AND STORED INTO DATABASE,
    i loaded the abc.class into oracle using loadjava command,
    AND also created the procedure based on loaded class,
    when i call the procedure, i got the error because i need to set classpath in oracle
    i.e i need to SET the classpath for the classes12.jar , i set the path in environment variables,
    when i run the .class file its working fine,
    can any one tell me , how to set the classpath in oracle, or reference to classes12.jar

    You don't set the classpath in Oracle; you set the environment variable CLASSPATH for your OS.
    For example, it may looks like this in UNIX:
    setenv CLASSPATH $CLASSPATH:$ORACLE_HOME/jlib/some_jar_file.jar

  • Set Classpath during runtime

    How can we set classpath to a .jar file during runtime. Is it possible to set classpath not other than editing a .bat file or by manually editing the global variables list????

    You need to implement you own Class Loader if you want to load a jar at runtime. Why would you like to do that in AS?

  • Setting CLASSPATH wthin a runnable Jar

    OK bear with me here, I'm not a total newbie.. really! I've built executable jars before, but with just the directories of raw classes inside.
    Now, I want to package up some jars, and point the classpath at these.
    So in my Ant build file I have
        <jar jarfile="CSVConverter.jar" basedir="." excludes="cvs CSVConverter.jar *.xml *.pdf *.xls *.bat">
           <manifest>
              <attribute name="Main-Class" value="CSVConverter"/>
              <attribute name="Class-Path" value=".;fclui.jar;dom4j.jar;fop.jar;avalon-framework-4.1.5.jar"/>
           </manifest>
        </jar>I added the "." to the claspath because it wasn't finding the Main Class. That seems wrong for a start!
    But it also can't find classes in the specified jars which ARE in the jar file, Ant tells me it's adding them, and I've checked.
    FYI, the error message is
    Exception in thread "main" java.lang.NoClassDefFoundError: com/fcl/xmlutils/CSVXMLReader$CSVSourceAnd that is in fclui.jar which is in the main jar: CSVConverter.jar.
    In case anyone is curious, it's a tool to use a SAX parser to create XML parse events from a CSV document, use XSL to massage the document into either the correct XML format for Excel (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnexcl2k2/html/odc_xmlss.asp), or FOP (http://xml.apache.org/fop/), and through fop to PDF. Basically the top line of the CSV is headers, subsequent lines are data, and out comes a very nicely formatted, and scaled report either Excel or PDF.

    The Class-Path is used as a hint to browsers to so
    they can down load additional JARs before they are
    called.
    This attribute is not use by java and the claspath
    cannot be set this way.Sorry, but this is just plain wrong!
    Please see http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Manifest
    "Class-Path :
    The value of this attribute specifies the relative URLs of the extensions or libraries that this application or extension needs. URLs are separated by one or more spaces. The application or extension class loader uses the value of this attribute to construct its internal search path."
    Still, JARs in a JAR will not work, AFAIK ...

  • How to use jar files without setting classpath

    Hi,
    I have a situvation, I can not set classpath, but i have to use jar files, how can I do that.

    URL[] urls = new URL[]{pathToJar, pathToAnotherJar, ...};
    URLClassLoader urlc = new URLClassLoader(urls);
    Now load classes within the jars loaded by the urlc classloader as needed. This is a limited approach, you can mostly use interfaces to work with classes loaded by the custom loader instance above and your existing classes.

  • Once i set classpath to servlet-api.jar, it doesnt Instantiate DbBean.

    I am using notepad editor. I am trying to instantiate a DbBean class inside the servlet's init() method.
    once i set (C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar) this path to compile the Controller servlet.
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>javac Controller.java
    Controller.java:5: package bean does not exist
    import bean.DbBean;
    ^
    Controller.java:14: cannot find symbol
    symbol : class DbBean
    location: class Controller
    DbBean dbbean = new DbBean();
    ^
    Controller.java:14: cannot find symbol
    symbol : class DbBean
    location: class Controller
    DbBean dbbean = new DbBean();
    ^
    3 errors
    C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes>
    this is my servlet
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import bean.DbBean;
    public class Controller extends HttpServlet
    public void init(ServletConfig config)throws ServletException
    ServletContext context = config.getServletContext();
    context.setAttribute("base_url",config.getInitParameter("base_url"));
    {color:#ff0000}DbBean dbbean = new DbBean();{color} {color:#0000ff}error showing in this line
    {color}dbbean.setDburl(config.getInitParameter("dburl"));
    dbbean.setUserName(config.getInitParameter("username"));
    dbbean.setPassward(config.getInitParameter("pwd"));
    /// database bean can be access from jsp page
    context.setAttribute("dbbean",dbbean);
    /// Load the data base driver
    try{
    Class.forName(config.getInitParameter("jdbcDriver"));
    catch(ClassNotFoundException e)
    System.out.println(e.toString());
    super.init(config);
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
    doPost(req,res);
    public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException
    String base = "/onlinetest1/";
    String url = base + "login.jsp";
    String action = req.getParameter("action");
    if(action!=null)
    if(action.equals("successlogin.jsp"));
    url = base + "successlogin.jsp";
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(req,res);
    public void destroy()
    System.out.println("Servlet stopped");
    This below class can be put inside bean folder( (ie)sub dir of controller servlet)
    package bean;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    public class DbBean
    String dburl="";
    String dbuser="";
    String dbpass="";
    public void setDburl(String url)
    dburl = url;
    public void setUserName(String uname)
    dbuser = uname;
    public void setPassward(String pwd)
    dbpass = pwd;
    What to do to rectify this, please help me why this error coming,

    hi,
    Actually i did my ordinary package compilation example below, its run correctly, but after set classpath to %tomcat-home%\common\lib\servlet-api.jar(for same programs its not working) this kinds of error coming.
    F:\shyam\test>javac first.java
    F:\shyam\test>java first
    main class
    DB Set Correctly
    F:\shyam\test>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar
    F:\shyam\test>javac first.java
    first.java:1: package bean does not exist
    import bean.DbBean;
    ^
    first.java:10: cannot find symbol
    symbol : class DbBean
    location: class first
    DbBean dbbean = new DbBean();
    ^
    first.java:10: cannot find symbol
    symbol : class DbBean
    location: class first
    DbBean dbbean = new DbBean();
    ^
    3 errors
    F:\shyam\test>
    In compilation it wont take DbBean class, please help me.
    thanks in advance,
    S.Shyam

  • Set classpath-Need Help

    I'm using JCreator LE and don't know how to set classpath to use java mailAPI
    Please help!!

    set CLASSPATH=%CLASSPATH%;c:\j2sdkee1.3\javamail-1.3\mail.jar;.
    set CLASSPATH=%CLASSPATH%;c:\j2sdkee1.3\activation\activation.jar
    set JAVA_HOME=C:\jdk1.3.1
    PATH C:\WINDOWS;C:\WINDOWS\WINDOWS;C:\DOS;C:\jdk1.3.1\BIN
    SET CLASSPATH=.;%CLASSPATH%

  • Set Classpath to .jar

    I try to create a step in sequence editor to execute a Java class developed by me (following the Computer.seq Java example given). The Java class uses API packaged in a .jar file.
    I tried to
    1. set the classpath to the jar file in Edit Java Class Path Location for Start JVM step and
    2. extract the classes in the jar into a directory set in Configure/Search Directories. 
    When executing the step, I got the following error:
    Details: Error executing substep 'Post'.
                 Cannot find class
    Error Code: -1500; User-defined error code.
    Please advice.
    Thanks

    Hi Wong,
    If you check this error code within the ReadMe in the example folder you can see that this error means "The provided class name was not found in the class path. Verify the class name and that the file containing the class exists in the class path."  Therefore, I think that you may have the incorrect class path set.  Although you selected in the Edit Java Class Path Location and browsed to your jar file, there are a couple things happening here that I believe are causing you to get the error.  First, the dialog is looking for a folder directory that contains your class files, not a jar file.  Also, make sure you point to a folder and not a specific file.  Also, if you look at the pre-expression of this step, you will see that it sets the class path to the example folder.  This value is overwriting anything that you place in the dialog box.  Therefore, delete the pre-expression for the step and then add the directory that your classes are located in to the Edit Java Class Path Location dialog box.
    Let me know if this helps you.
    Thanks,
    Caroline Tipton
    Data Management Product Manager
    National Instruments

  • How to set classpath in WinXP Home edition

    Hello everyone,
    Recently I have try to run the HelloWorld java code, but it come up with a error. (Exception in thread �main� java.lang.NoClassDefFoundError: HelloWorld)
    Java programming Code:
    public class HelloWorld {
    public static void main (String args[]) {
    System.out.println("Hello World!");
    I also try to compile another simple program, and it come up with the simpler error, (Exception in thread �main� java.lang.NoClassDefFoundError: Add16And23)
    Java programming Code:
    public class Add16And23
         public static void main (String[] args)
              int sum;
              sum=16+23;
              System.out.println("The sum of 16 and 23 is " + sum);
    HOW CAN I FIX THIS, I read other threads before, it say some about class path.
    Do anyone know how to set it, in winXP?
    Do anyone know the whole path that I should put in, in winXP?
    What should I type in the (User variables for windows) and (System variables).
    I have :
    * (j2eesdk-1_4-dr-windows-eval) downloaded and installed;
    *&#61623;WinXP Home edition Version 2002 Service Pack 1
    * My current Java path are (C:\Sun\AppServer\jdk\bin) in the (User variables for windows).
    Please help!!!
    Thank you all!!!

    I'm also windows xp.
    fllowing example:
    java_home=c:\j2sdk1.4.2_03\bin
    classpath=c:\j2sdk1.4.2_03\dt.jar;c:\j2sdk1.4.2_03\tool
    .jarThis won't fix a thing.
    When you run, do it like this:
    java -classpath . HelloWorldNote the "dot" after -classpath. That tells the class loader to look in the current directory for the .class files it needs.
    Read about how to run the javac.exe and java.exe tools in your javadocs. You'll have to learn about CLASSPATH. - MOD

  • Setting Classpath in linux

    Hi !! Can anyone help me in setting classpath in linux to run servlets/? I tried using this command..but didnt work
    export CLASSPATH="$CLASSPATH:/usr/share/tomcat5/server/lib/servlets-common.jar"
    Thanks
    Nive

    in ur autoexec.bat file write the following
    set PATH=C:\jdk1.5.0_04\bin;%PATH%
    set JAVA_HOME=C:\jdk1.5.0_04
    set
    CLASSPATH=.;C:\jakarta-tomcat-5.5.9\common\lib\servlet
    -api.jar;C:\jakarta-tomcat-5.5.9\common\lib\jsp-api.ja
    r;C:\Servlets+JSP;..;..\..;C:\jakarta-struts-1.2.4\lib
    \struts.jarThis response is meaningless. Principally because the OP specifically mentioned the use of LINUX. Not Windows.
    I've taken the advice of other forum users by avoiding a system level classpath variable. I define the classpath each time I compile and run. Working on Linux I tend to use command line argument files ( http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html#commandlineargfile ) which eliminates the need to redefine the classpath each time I compile or run my classes and apps. But others may do things differently.
    Here is a website you might want to check out which pertains to setting the classpath on Solaris and Linux.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html

  • How to set classpath for classes in war files

    Hi All,
    After deploying the WAR file I could access the JSP files but gives classnotfound exception when the information is expected from the java servlet.DO I need to set the classpath if yes how to do for the war file.
    thanks

    The web.xml,file structure and error is below let me know if more information is required.
    As you said weblogic is looking for the classes in lib directory inspite of having the classes in web-inf/classes directory.
    web-app>
    <servlet>
    <servlet-name>ControllerServlet</servlet-name>
    <servlet-class>com.test.site.pds.Controller</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/controller</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>
    File Structure:
    C:\test\PDSWebApp\WEB-INF\classes\com\test\site\pds\*.class
    PDSWebApp
         css
         html
         images
         javascript
         jsp
         WEB-INF
         classes
         com/test/site/pds/*.java
         lib
         servlets
    The error:
    javax.servlet.ServletException: [HTTP:101249][ServletContext(id=18129862,name=PdsApp,context-path=/PdsApp)]: Servlet class com.test.site.pds.Controller for servlet ControllerServlet could not be loaded because the requested class was not found in the classpath C:\bea\user_projects\domains\mydomain\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\PdsApp.war;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\classes12.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\commons-beanutils.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\commons-collections-2.1.1.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\commons-lang-2.0.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\displaytag-1.0.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\jstl.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\WEB-INF\lib\standard.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp\jarfiles\_wl_cls_gen.jar;C:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_PDSAPP_PdsApp.
    java.lang.ClassNotFoundException: com.test.site.pds.Controller.

Maybe you are looking for