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 ...

Similar Messages

  • 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

  • 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

  • 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.

  • Problems with CLASSPATH in a executable jar file

    Hi there
    I'm having a problem that I don't know how to solve. My generalq uestion is:
    "Why isn't my CLASSPATH (java.class.path) forwarded into ar unnable class inside a jar file?"
    The situation is:
    I have made a runnable jar file containing an ant build.xml file, a jar file containing some patch files, and a class called AntLoader.class. AntLoader are the file that are executed (inserted into the manifest). This works. The class are executed, but it can't find the package needed for starting ant.
    ant.jar is in my CLASSPATH, and therefore everything works fine if I'm running AntLoader outside the jar file.
    I know that I can use different ClassLoader classes for dynamicly loading of a class, but then I need a path to where ant.jar is located. And then again my system wont be general. The jar file is supposed to be distributed as a system patch to customers. And their location of where ant is installed will not be the same.
    So what I'm looking for is a way to pass my CLASSPATH from my environment on to a jar file. Is that possible?
    running java -classpath "${CLASSPATH}" -jar cpc.jar doesn't help at all. The java.class.path is still set to cpc.jar when I'm executing the AntLoader class inside cpc.jar.
    Can anyone please help me?
    Brgds
    Jakob

    've found the solution to the problem. You have to use the -Xbootclasspath/a parameter when running java.
    Example on unix:
    java -Xbootclasspath/a:${CLASSPATH} -jar test.jar
    Brgds
    Jakob

  • How to create runnable JAR in Eclipse

    I have a project in Eclipse with many classes.
    Whenever I try to create a runnable JAR, the JAR file created always contains all the classes of the project, regardless whether they are really used or not.
    Is it possible to create a runnable JAR in Eclipse, excluding the classes of the project which are not strictly necessary for a given launch configuration?

    krige wrote:
    I have a project in Eclipse with many classes.My condolences on using a build system that apparently has grabbed you by the short & curlies. That can be painful.
    Note that:
    1) Eclipse can use Ant style build.xml files for controlling most aspects of a build (that are worth mentioning).
    2) We provide no support for Eclipse on these groups, but since Ant typically defers to a core set of tools in the SDK, you can usually get away with asking an Ant related question.

  • 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

  • Runnable JAR from Eclipse with DLL

    Hi,
    Is it possible to export a runnable jar from Eclipse that includes and uses a dll?
    My simple application uses an 'external' API - JIntelliType - a jar file and a dll belongs to it.
    I can run the project fine from Eclipse, but I can't export it to runnable jar. I am a bit lost among classpath, path, build path, native library location, referenced library,..
    But maybe it doesn't matter because after trying to look this question up on the net, I am not sure if it is possible to do it with Eclipse (not without additional plugin at least).
    Could somebody please help me with this?
    Thank you in advance!
    lemonboston

    Your question is that of deployment. In Eclipse you setup your development environment to include native binaries in the projects working directory. As soon as you leave Eclipse you do not have its facilities anymore and you need to make do with what the JDK has to offer you.So your real question is: I have a jar and a DLL, the jar depends on the DLL. How do I run the application such that the DLL can be loaded by it?
    The answer is: you can provide through a system property (java.library.path) which directory Java (and ultimately the operating system) should scan for native binaries, or you can simply put the DLL in the same directory as the jar. The current working directory (the directory where Java is invoked) is always on the binary search pat of the operating system.
    The documentation for the java tool is here:
    http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html
    To pass a system property as a parameter you would do something like:
    java -Djava.library.path=path/to/libs -jar yourjar.jar

  • Package does not exist even though I set classpath right!

    Hi, my JSP got an error message saying "Package does not exist" at line
    <% import ="org.jfreechart.*"%>
    And I have put the myjar.jar file containing the above classes into blabla\WEB-INF\classes,(where blabla is my current working directory) and set my classpath= blabla\WEB-INF\classes
    It does not either if set classpath= blabla\WEB-INF\classes\myjar.jar
    Anybody could give suggestion? By the way I am using Tomcat.

    your .jar files should be in WEB-INF/lib

  • Help with setting classpath

    Hi All,
    I am new to servlets and JSP. I have a question regarding setting Classpath. My development directory structure is like this c:\..\desktop\java\project1\src\com\eg\web\e1.java. Servlet.jar file is in C:\Program Files\Apache Group\Tomcat 4.1\common\lib. I tried setting Classpath in windows 2000 using control panel=>System utility by this command
    SET CLASSPATH=.;c:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar . I try to compile my program by going into the whole development directory structure C:\..\src\com\eg\web using javac e1.java. But I get the error "package javax.servlet does not exist". Can somebody help me resolve this?
    Thank You in advance
    Jaya

    Question 1: Are you using an IDE?
    [IDEs ignore the system classpath]
    Question 2: Did you try setting the classpath using the -cp option for javac, if you are not using an IDE?
    [you could also try to print the classpath on command line to check if it has taken effect]

  • Setting Classpath on Windows 2000 box

    I have written a java application that is deployed to a Windows 2000 box. This application requires that a number of .jar files be included in the classpath, but it appears Windows 2000 imposes a maximum character length on the classpath variable because when I try to include all my .jar files in the classpath variable, the string is getting cut-off after a set number of characters. For example, I would like my classpath set to c:\classes\jar1.jar;c:\classes\jar2.jar;c:\classes\jar3.jar, but Windows 2000 only recognizes c:\classes\jar1.jar;c:\classes\jar2.jar;c:\cl. This causes my application to take java.lang.NoClassDefFoundExceptions since all the .jar files do not get included in the classpath.
    Does anybody know of a way around this issue? I would really like to avoid extracting the contents of my .jar files to a directory structure. Thanks for your help.

    I forget what the limits in Windows are, but they're a lot bigger than the size you need. I just set my classpath to that string in Windows 2000 with no problem. I believe Windows has a limit on the total size of the environment: maybe you have a whole lot of other environment variables set that you could dump. More likely, the problem has nothing to do with a Windows size limit, and you're getting cut off somewhere else.

  • Setting Classpath on windows platform

    Hello
    I was trying to set classpath of "D:\documentum\config" in my environment variable , i was doing it through command
    prompt , the command i was implementing was
    set classpath=D:\documentum\config;
    but the when i was closing command prompt , the environment variable in windows named as ClassPath was not updating
    i have also tried this command
    set classpath=%classpath%;D:\documentum\config;
    this also having the same result , so how can i set this property through command prompt
    Regards

    You can permanently set command line environmental variables through the advanced settings in Windows. You have to hunt around for it a bit, it is somewhere behind opening the right click properties of "my computer" (or whatever it is called in your flavor of Windows) and then choosing advanced. An "environmental variables" tab should be present there.
    BUT! I would not advise you to set a classpath variable unless you fully realize that is only to make your development life a bit easier when working on the command prompt. When making your application ready for deployment the classpath must be managed without the variable. A script could work, or packaging everything up as an executable jar. When you start to work with an IDE like Eclipse or Netbeans you don't need that variable at all any more.

  • Setting classpath in netbeans ide5.0

    i don't know how to set classpath in netbeans ide5.0 for
    MySQL driver and its jar file.

    Then you should read the Netbeans documentation:
    http://www.netbeans.org/kb/50/using-netbeans/index.html

  • Problems setting classpath...

    hello guys...i am having a problem with what should be a very simple operation...
    the classes i define are stored in the classes directory..inside, each package has its own subdirectory...
    classes
    beans
    User.class
    Cart.class
    i have tried to change my classpath to reflect this location and instruct the compiler as to where to find those classes..
    i have used the set Classpath command...
    SET CLASSPATH=.;C:\Tomcat\common\lib\servlet-api.jar;C:\Tomcat\common\lib\mysql-connector-java-3.1.13-bin.jar;
    C:\Tomcat\webapps\theagent\WEB-INF\classes beans.User;
    but when i try to import beans.User in another class..it doesnt compile and tells me that the package doesnt exist...
    please help....what else do i need to check to make sure the configuration is as it should be...
    p.c User.java started with package beans;
    thanks

    That is correct because your beans.User class doesn't contain a
    public static void main(String[] args) method, iow you can't run it by itself.i dont want to run the class by itself... i just want to import beans.User;
    but it says that no such package exists...Then you have to be a bit more clear. You mentioned this command line:java -classpath C:\Tomcat\common\lib\servlet-api.jar;
    C:\Tomcat\common\lib\mysql-connector-java-3.1.13-bin.jar;
    C:\Tomcat\webapps\theagent\WEB-INF\classes beans.User;This sets the classpath pointing to two jars and a 'classes' directory.
    You're trying to run the 'beans.User' class which I presume is stored
    in a subdirectory of that 'classes' directory.
    The java command works like this:java -classpath <jars and dirs here> package.YourClass... so you were trying to run your beans.User class all by itself. It doesn't
    contain a main method hence the runtime diagnostic. btw, I don't know
    why you appeded that whole thing with a semicolon.
    kind regards,
    Jos

  • Setting classpath in bat file

    Hi,
    I'm trying to call my java app from a bat file, normally I put all references to jar files hard coded in the bat file, but now I would like to loop over a lib directory and add all jars in that directory to the classpath:
    I tried the FOR loop of Windows batch like this:
    FOR /R .\lib %%G IN (*.jar) DO set CLASSPATH=%CLASSPATH%;%%G
    but the classpath only contains the last jar file of the directory, what is wrong with that line? A for loop on unix is no problem.
    THX

    Hi,
    I had teh same need, but neither
    FOR /R .\lib %%G IN (*.jar) DO set CLASSPATH=!CLASSPATH!;%%G
    works for me nor
    FOR /R .\lib %%G IN (*.jar) DO set CLASSPATH=%CLASSPATH%;%%G
    I have set the "ENABLEDELAYEDEXPANSION" also
    Regards

Maybe you are looking for