How to run a java program using additional jar files

Hi everyone in the forum,
i ve created an app using the hFreeChart in eclipse, so i added them as external jar files and tested the program.
now my problem is that the program should run using a terminal in win and i do not know how can i do to make the command line or the system to find them, i added to the path but i read somtehing about classpath, but i have no idea. if anyone can help?
thanks in advanced

Actually, the best way to prepare a program for regular running is to make it an executable jar file, which means adding a manifest file which contains (at least) a Main-class: and a Class-Path: line. Referenced class libraries typically sit in a lib directory next to the java file. Then you can run it using java -jar myprog.jar.
Failing that create a batch file or link that supplied java with command line parameters including a -classpath=
Using the class path environment results in too much contention between competing values of it.

Similar Messages

  • How to run a java program via a batch file,which is called from a webserver

    REM This batch file runs the Spider with the [-v] option.
    REM Lines 51 through 54 are simple DOS commands..they call the Spider
    REM The location of the Spider package is the important piece of information here...
    REM a batch file has access to the whole computer where the server resides.
    setlocal
    set JDK=C:\j2sdk1.4.1_01
    set PATH=%JDK%\bin;.;%PATH%
    CLASSPATH=%JDK%\jre\lib\*.jar;.;%JDK%\jre\lib\ext\*.jar;.;%CLASSPATH%
    java spiderpackage.EntryPoint -v
    endlocal
    I am trying to call this batch file from my web server but I am unable to capture the result.I tried to append the result to a file but It writes nothing to it.What should I do to proceed?

    I am not entirely sure if this is analogous, but I once wrote a PHP script uner Linux that invokes java and returning the output. I found that it was necessary to pipe the output of the Java program from stderr to stdout in order to properly receive it in PHP. The command would be as follows:
    java spiderpackage.EntryPoint -v 2>&1
    The pipe syntax (2>&1) should be exactly the same under MSDOS. So add that, and then continue as normal (appending it to a file or whatever else you want to do). Hope that helps

  • How to run a java program in another folder

    Hello!
    I want to run for example the java class file in the path ./sourcecode/javafile.class. It works fine if I do the following:
    cd sourcecode
    java javafile
    but it cannot work if I do:
    java sourcecode/java
    The error it outputs is NoClassDefFoundError.
    Can someone tell me how to run a java program in another folder
    thanks a lot.

    You need to specify the classpath using the -cp flag when running. so instead of
    "java sourcecode/javafile"
    Try
    "java -cp sourcecode javafile"

  • Running a java program via a batch file

    I am unable to run a java program from a batch file that I created.
    spiderpackage.EntryPoint is a class file which I am trying to run with a -v option to output something.What should I do to get the output?
    echo ^<html^>^<body^>
    echo hello^<br^>
    call java spiderpackage.EntryPoint -v
    echo ^</body^>^</html^>

    This has nothing to do with java programming. Have a look at the windows help for the call command.
    The echo <html> stuff doesn't make sense. What's it for?
    The command in you batch file should be:
    java -cp . spiderpackage.EntryPoint -v
    assuming that java is in the system path, and the EntryPoint.class is in a directory called spiderpackage which is a subdirectory of your current working directory

  • URGENT: How to run a Java program from a different directory?

    Hi.
    How do I run a Java program from a directory that the file is not located in? So lets say im in c:\Java. But the file is in c:\Java\abc\efg\.
    What would be the command to run the Java file from c:\Java.
    I can't remember it and I need it asap.
    Cheers.

    If the class you are trying to run is MyApp.class, try
    c:\Java\>java -cp abc\efg MyAppThe actual classpath you specify will depend on whether or not MyApp.class is in a package (I've assumed it isn't) and whether or not any 3rd party jars are involbed (I've assumed not).
    Edited by: pbrockway2 on Apr 1, 2008 6:42 PM
    The command arguments read as "Run the MyApp class using as a classpath abc\efg relative to here (c:\Java)".

  • How to run a java program without Java Compiler

    I have a small project and I want share it with my friends but my friend'pc have not
    Java compiler.
    for example, I writen a application like YM, then 2cp can sent,receive messege. My cumputer run as Server, and my frien PC run as client.
    How can my friend run it? or how to create an icon in dektop tu run a java program..??..
    (sorry about my English but U still understand what i mean (:-:)) )

    To run a program you don't need a Java compiler. Just the Java Runtime Engine. That can be downloaded from the Sun website and comes with an installer.
    You could then turn your application into an executable jar file and start it somehow like jar myYM.
    There is also software that packs a Java program into an executable file. I've never used that but one that comes to my mind is JexePack. It's for free if you can live with a copyright message popping up every time you start the program.
    http://www.duckware.com/jexepack/index.html

  • How to run a java program in command prompt

    hi i want to run a java program from in command prompt from another directory
    i want to run a file named First in C:\Program Files\Java\jdk1.6.0_07\bin
    so when i give the command
    java "C:\Program Files\Java\jdk1.6.0_07\bin\First"
    it doesnt works it shows
    C:\>java "C:\Program Files\Java\jdk1.6.0_07\bin\First"
    Exception in thread "main" java.lang.NoClassDefFoundError: C:\Program Files\Java
    \jdk1/6/0_07\bin\First
    Caused by: java.lang.ClassNotFoundException: C:\Program Files\Java\jdk1.6.0_07\b
    in\First
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: C:\Program Files\Java\jdk1.6.0_07\bin\First. Pro
    gram will exit.

    but it prints
    C:\>java -cp "C:\Program Files\Java\jdk1.6.0_07\bin\" First
    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)
    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    A ; separated list of directories, JAR archives,
    and ZIP archives to search for class files.
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -version:<value>
    require the specified version to run
    -showversion print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
    include/exclude user private JREs in the version search
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    -agentlib:<libname>[=<options>]
    load native agent library <libname>, e.g. -agentlib:hprof
    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
    load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
    load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
    show splash screen with specified image
    C:\>

  • How to run a java program in windows 2003 server from unix server.

    Hi ,
    I want to run a java program in windows 2003 server from unix machine ..
    will RMI helps me to obtain this.
    Please tell me the procedure to do this.
    Thanks in advance,

    rmi,web services,corba,web 2.0,xml,xls,dtd,rss,ruby on rails,https,soap,tags,blog,podcast,google

  • How to run a java program remotely

    hi,
    i have a simple hello-world java program on my windows machine.
    is it possible to run this program remotely from a linux server?
    any suggestions, links to suggestions will be helpful. thanks!

    i think that would be a problem for me, so i will need to use some other approach. what i'm trying to do actually is that we have a university server which is set up so that students can have combination fo shell and cgi scripts in their home directory and with that, they can have web pages.
    but students cannot use that server to run java applications. so to work around that, i was hoping that i can have my java application, and the database on my own windows machine, and be able to invoke the java program from the shell script on the linux server and once i have my ouptut, i can display that on the web page with CGI script.
    is there any other practical approach that i can use to accomplish the above?

  • How to run a java program in the JVM of an already running program?

    As far as I know about JVM, each time we run a program a separate instance of JVM is created where the program runs. Correct me if I am wrong.
    Is there any way for another program to execute itself in the same JVM?
    Currently I am working on JFCUnit which is a tool used to automate swing applications. I am trying to automate JConsole.
    If I open "JConsole.exe" through a program and then try to get the handles using JFCUnit, things are not working.
    If I use JConsole.jar in JDK/lib and create a new instance of JConsole and then try to get the handles using JFCUnit, I am able to proceed with automation.
    But here comes the problem :-
    The application which needs to be automated through JConsole requires it to be started with few arguments, which is as follows:
    %JDK_HOME%\bin\jconsole -J-Djava.class.path=%CLASSPATH% -J-Dcom.sun.management.jmxremote.ssl=false -J-Dcom.sun.management.jmxremote.authenticate=true -J-Djmx.remote.protocol.provider.pkgs=oracle.oc4j.admin.jmx.remote "service:jmx:rmi://localhost:23791"So this problem can be solved in two ways,
    Either
    1. JFCunit could be made to recognize the JConsole.exe which would be running is a different JVM.
    OR
    2. JConsole.jar to be used in a way so that it takes the required arguments, hereby an instance of JConsole would be created that too in the same JVM as that of the program.
    I am more interested in the first solution as it would definitely be helpful in other projects as well.
    Please let me know if any other solution is possible.
    Any kinda solution is appreciated :)
    Thanks in advance.

    Give a look at Terracota.
    http://www.terracottatech.com/

  • How to run a Java program without the command line.

    Is there anyway to create a Java program that runs like most programs do in Windows ,by double clicking on their icons?
    Thanks,
    Vance

    http://www.ej-technologies.com/products/exe4j/overview.html
    Looks kinda cool. Most java-2-exe programs are usually way too expensive and wont work with GUIs and require other dlls/libraries...

  • Running a java program using URLClassLoader

    I have been developing text editor for my final project which can compile and run java prorams.
    this is the code that i have written for running the class file that is created after compilation---
    import java.net.*;
    import java.net.URLClassLoader;
    import java.net.URL;
    import java.io.File;
    import java.lang.reflect.*;
    public class runMethod extends ClassLoader{
         public void run(String dir, String f){
              File file = new File(dir);
              File[] files = file.listFiles();
         URL[] urls = new URL[files.length];
              try{
                   URL url = file.toURL();
              }catch(MalformedURLException e) {
         System.out.println("MalformedURLException: " + e.getMessage());
                   ClassLoader loader = new URLClassLoader(urls);
              try{
                        Class clazz = Class.forName(f, true,loader);
                        Method method = clazz.getDeclaredMethod("main", new Class[] { String[].class });
                        method.invoke(null, new Object[] {});
                   } catch (Exception ex) {
                   System.out.println(ex.getMessage());
    But the output it gives me is not the running program but "null". please help me in figuring out what is the problem and why is it not running the class file and giving the output.

    Here a complete example.
    Suppose that your workspace is C:/java/projects/, that your project is called myproject and the build directory is called classes (myproject/classes/)
    create the class MyTargetClass in a package called test1 :
    package test1;
    public class MyTargetClass {
         public static void main(String[] args) {
              System.out.println("Hello from "+MyTargetClass.class.getName());
    }Create the class RunMethod in a package called test2 :
    package test2;
    import java.net.*;
    import java.io.File;
    import java.lang.reflect.*;
    public class RunMethod {
         public void run(String dir, String f) {
              URL[] urls = null;
              try {
                   // Convert the file object to a URL
                   File myDir = new File(dir);
                   URL url = myDir.toURL();
                   urls = new URL[] { url };
              } catch (MalformedURLException e) {
                   e.printStackTrace();
              try {
                   // Create a new class loader with the directory
                   ClassLoader cl = new URLClassLoader(urls);
                   // Load in the class
                   Class clazz = cl.loadClass(f);
                   // Create a new instance of the new class
                   //MyTargetClass= (MyTargetClass) clazz.newInstance();
                   Method main = clazz.getDeclaredMethod("main", new Class[] { String[].class });
                   main.invoke(null, new Object[] { null });
              } catch (Exception e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new RunMethod().run("C:/java/projects/myproject/classes/", "test1.MyTargetClass");
    }Compile and run the RunMethod class.
    Hope That Helps

  • How to make a java-program to a exe file runing on windows?

    i kown that there were many topics on this problem.
    i want to kown how many kinds method to do this i can use now!
    i met a java-program can run on windows,but i don't find ant *.class
    files and *.jar files.it's extended file type is ".ese".
    thanks very much

    There are commercial products that allow you to do this (e.g. InstallAnywhere from http://www.zerog.com).
    One issue is that you have to decide whether you want to bundle a JRE with your program or not. If you do (and you should, in these days of XP shipping without any VM of its own), your program will be a minimum of about 9MB + whatever you actually add as part of your program :-).
    In any case, this is not a trivial undertaking.

  • To run a java program via a batch file,when called from a web server

    REM This batch file runs the Spider with the [-v] option.
    REM Lines 51 through 54 are simple DOS commands..they call the Spider
    REM The location of the Spider package is the important piece of information here...
    REM a batch file has access to the whole computer where the server resides.
    setlocal
    set JDK=C:\j2sdk1.4.1_01
    set PATH=%JDK%\bin;.;%PATH%
    CLASSPATH=%JDK%\jre\lib\*.jar;.;%JDK%\jre\lib\ext\*.jar;.;%CLASSPATH%
    java spiderpackage.EntryPoint -v
    endlocal
    I am trying to run this batch file from my web server.I can see nothing on my browser.I can run the same program from my machine but unable to run from web server.what should I do?

    I am making my question more clear...
    I have a Windows batch (*.bat) file that echoes some html, then calls a java program the output of which is html as well, then echoes the final html.
    To make sure that the java program gets properly executed, I set the necessary environment variables (e.g., JDK, PATH, CLASSPATH, etc.). The script looks something like this:
    setlocal
    set JDK=path_to_JDK
    set PATH=path_to_java
    set CLASSPATH=path_to_java_classes
    echo ^<html^>^<body^>
    call java foo
    echo ^</body^>^</html^>
    endlocal
    The idea, of course, is to call this script through a browser, on a web server.
    Curiously, both echo lines return to the browser just fine, but any output from
    the java program (which just writes html to STDOUT) does not make it back.
    Can someone explain to me why this is happening? How do I set things up so that the output (STDOUT and STDERROR) from the java program make it back to the browser?

  • How to Run a simple program using JMS Queue.!!

    Hi All,
    I am trying to run simple program on JMS Queue.
    Using SOA Suite 10.1.3.2
    I created a connection factory and queue using EM.
    Connection Factory => Domain : Queue JNDI Location : jms/sidConnectionFactory
    Queue Name : SidQueue JNDI Location : jms/SidQueue
    Tried running a simple java class to send the messages to queue.[Pls find the file attached].
    Getting this error
    javax.naming.NamingException: META-INF/application-client.xml not found (see J2EE spec, application-client chapter for requirements and format of the file)
    at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getRequiredClasspathResource(ApplicationClientInitialContextFactory.java:239)
    at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getArchive(ApplicationClientInitialContextFactory.java:161)
    at oracle.j2ee.naming.ApplicationClientInitialContextFactory.getInitialContext(ApplicationClientInitialContextFactory.java:111)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
    Can some one tell me how i need to create this file and where to place this[i.e is this need to be placed in  my project or some directory structure of <SOA-HOME>
    Thx,
    Siddhardha.
    Code:
    package demo;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Properties;
    import javax.jms.*;
    import javax.naming.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class JMSQueue {
        public static void main(String args[])
    QueueConnection queueConnection;
    QueueSession queueSession;
    //private MessageProducer producer;
    QueueSender queueSender;
    try {          
    String message = "Test";
    String connectionFactoryName = "jms/sidConnectionFactory";
    String destinationName = "jms/SidQueue";
    /*Do i need to use this .......
    * If so where is the error in below statements...
    * Properties env = new Properties( );
    // ... specify the JNDI properties specific to the vendor
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "welcome");
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.ApplicationClientInitialContextFactory");
    env.put(Context.PROVIDER_URL,
    "ormi://localhost:23791");
    Context ctx = new InitialContext();
    // Get the connection factory.
    QueueConnectionFactory cf = (QueueConnectionFactory)ctx.lookup(connectionFactoryName);
    // Get the destination.
    Queue destination = (Queue) ctx.lookup(destinationName);
    // Use the connection factory to create a connection.
    queueConnection = cf.createQueueConnection();
    // Start the connection.
    queueConnection.start();
    // Use the connection to create a session.
    queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    // Use the session and destination to create a message producer and a message consumer.
    //producer = queueSession.createProducer(destination);
    queueSender = queueSession.createSender(destination);
    TextMessage msg = queueSession.createTextMessage(message);
    queueSender.send(msg);
    queueSession.close();
    queueConnection.close();
    catch (Exception ex) {
    ex.printStackTrace();
    * Attached following libraries to the Project
    * jms.jar
    * optic.jar
    * oc4jclient.jar
    */

    Hi,
    You need to change the INITIAL_CONTEXT_FACTORY to com.evermind.server.RMIInitialContextFactory.
    Regards,
    Sandeep

Maybe you are looking for

  • Getting Tomcat 4.1 to call EJBs in WLS 8.1

    I know this is not necessarily a new topic, but we're upgrading our Tomcat 4.1 -> WLS 5.1 to a Tomcat 4.1 -> WLS 8.1 configuration. Firstly, has ANYONE got Tomcat 4.1.x to work with a post 5.1 container at all? Ever? We are using the T3 protocol to t

  • General QUestion about error handling

    Hello,    I am writing my own VI's to communicate with my hardware. Each one of the VI's incorporate numerous error checking routines to detect if the desired operation completed correctly. If error(s) are detected with a VI, the "Bundle by Name" VI

  • Item Categories Display in Contract

    Dear All, In my contracts 1) In the development I am able to see the item categories ( through F4) assigned to that contract Type (No Restriction). 2) While in Production I am not able to view any Item categories ( through f4) unless I enter material

  • AIR installation error through browserAPI

    Hi, I am using the badge.swf for my adobe AIR app. installation. I am gettong the following error:- Config: OS - Microsoft XP Professional Service Pack 3 CPU - Intel Core 2 Duo T9600 @ 2.80GHz AIR Vresion - 2.6.0.19120 My app-xml has first line as < 

  • Jump Query asking for Sign on again in Portal

    Hi All, I have a jump query (target is a URL not a web template) and when we click on goto/xyz_report the system is asking login again. On other reports when the target is a web template the system follows the SSO (we have SSO on the portal and once