Running jar files from the command line

I have always felt it would be useful to run a jar file from th command line in EXACTLY the same way as an EXE. On some systems, typing MYAPP.JAR will run the app, but doesn't output and command line data, so it only works for GUI apps. I've come up with a tiny C program that runs java -jar xxxx.jar for you.
#include <stdio.h>
#include <string.h>
#include <process.h>
void main(int argc,char *argv[])
     char cmd[1024];
     strcpy(cmd,"java -jar ");
     strcat(cmd,argv[0]);
     strcat(cmd,".jar");
     for(int arg=1;arg<argc;arg++)
          strcat(cmd," ");
          strcat(cmd,argv[arg]);
     system(cmd);
}Simply compile this to an exe, rename the exe to the name of your jar file and put it in the same directory. Then just type 'MyJarFile' (no jar extension) and it should run. It passes all command live args as well. Comments ?

Here's a better version. The JAR and the EXE can be anywhere in the PATH:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
void main(int argc,char *argv[])
     char jar[1024];
     char cmd[1024];
     strcpy(cmd,argv[0]);
     strcat(cmd,".jar");
     _searchenv(cmd,"PATH",jar);
     strcpy(cmd,"java -jar ");
     strcat(cmd,jar);
     for(int arg=1;arg<argc;arg++)
          strcat(cmd," ");
          strcat(cmd,argv[arg]);
     system(cmd);
}

Similar Messages

  • Compress/zip files from the command line in Windows 7?

    In Windows 7 is there a native way to compress or zip files from the command line?  I'd like to do it without installing any third-party utilities such as 7Zip.

    I fully agree that Compact is not the answer. There are additional concerns with the Compact command. It enables disk compression which is a total no-no. Very bad! It makes your computer very slow and is quite difficult to undo. The only time anyone should
    use this command is when they're removing disk compression because someone turned it on to save space.  Turning this off has to be done by booting into the recovery console, if my memory serves me correctly, and it's a real nuisance.  So
    definitely no to the Compact command.
    If you wanted to compress files before sending them to another drive, or over a network, or by email, then Compact wouldn't actually help at all because the files have to get uncompressed whenever they're accessed, especially before sending them anywhere. 
    When I say accessed, I mean that just looking at a file triggers the OS to decompress it in the background and present you with an uncompressed version of it then letting you change it and recompressing it again for storage every single time you access the
    file, which is why your machine gets slower.  If you have folders or files that have blue text instead of black, then you've probably already made this mistake.
    I would also like to know if there is a built-in command for zipping files/directories, or, if there isn't such a thing built into Windows, then I would like to know if this is feature is accessible through Visual Studio, which would be just as good as having
    a command-line program for those of us that do a bit of programming.
    If anyone knows if MS provides such a feature, either by command-line or through an API, then I'd love to hear about it.  Good luck to those of you that have disk compression turn on.

  • Run javascript (not in a jsx file) from the command line extendscript

    Hi all,
    I was wondering if anyone knew how to run javascript from the command line in Extendscript (meaning Extendscript would be the target application). I know about the -run command line flag in which allows you to run a .jsx script from the command line but what I'm looking for similar syntax to run a script directly without needing to put it in a file. For example I have tried (obviously unsuccessfully):
    C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\ExtendScript Toolkit.exe -run "alert('Hello World');"
    Thanks!

    You might be looking for something like this: javascript - Is it possible to execute JSX scripts from outside ExtendScript? - Stack Overflow
    Although that one is about executing JSX files, the solutions given (Applescript as well as COM/VBScript) can be adapted to simply run a javascript code snippet rather than JSX file because the solutions simply call the Adobe app's Applescript/COM API to "execute javascript" (actually execute ExtendScript technically), and in the solution, they using includes to pull in the JSX file. You'd simply replace the include with actual javascript code snippet inserted in.
    Though this would then require you to run a VBScript, Applescript, or other script (that calls the COM/Applescript API) rather than the ESTK command line option.

  • Get the absolute path and filename of the file from the command line

    Hi,
    when we run the class we give the command
    java <filename>
    How can I capture the filename given above and get its absolute path inside the
    public static void main(String [] args){}
    args[0] gives me the command line argument after the filename. How do I capture the filename itself from the command line argument and also get that files absolute path
    Thanks

    I don't know of any way to capture the java command input, but there are ways to find out where the application is being run from. (the "absolute path")
    http://forum.java.sun.com/thread.jsp?forum=31&thread=335394

  • Running powewrpc programs from the command line

    I am trying to run a powerpc application (quicken) from the command line. I want to log into the mac over my local network and run a powerpc program, but I get the following when I try it:
    cannot execute binary file
    I am logging in via ssh, and am running the X11 package from a different unix system which also runs X11.
    How do I get the application to execute? (it runs fine from the desktop).

    I am sitting at a Sun Solaris machine (it runs X11R6
    and Matif). I want to run Quicken, which is on the
    mac mini. I log into the mac with ssh -X. I find the
    Quicken program, but the permissions are set to 644
    (read, but not execute). If I change the permissions
    and try to run the program I get teh error message
    "cannot execute binary file".
    The window interface of the Mac is not X11: so you cannot output it on another X system. Is is not like connecting to another Un*x system.
    Said that, you should be able to launch a program, but you cannot see the output. However, usually Macosx applications are bundles with some executable inside, not directly an executable file: .app files are folders, not files. In order to launch such kind of apps, you have to use the open command I suggested in the previous post.
    I have no idea what VNC is. If this is how I can do
    this, then please provide me a link to it.
    VNC is a screen sharing application, just like Windows Remote Desktop. You may install a VNC server on your mac mini, and then connecting with a VNC client you will see all your computer screen as if you were there. It is cross platform, so no matter which is your client (including mobile phones).

  • How do I create an AppleDouble "dot-underscore" file from the command line?

    We're going through a process of migrating NetWare shares to Windows shares (without File Services for Macintosh) where I work. One concern is that the NetWare shares are shared as AFP volumes to the Macs. All the finder info and metadata for the files is thus stored natively and invisible to all the servers involved in the migration. If the Novel migrator or robocopy copy the files, resource forks and metadata are lost.
    The procedure I've provided the migration team involves making a UFS disk image, identifying files on the NetWare share that have Mac resource forks or metadata, copying the files from NetWare to the image one-by-one (whereby the OS creates the AppleDouble dot-underscore files), and then copying the dot-underscore files back to the NetWare share so that when either migration tool is used, the files correctly appear on the Windows shares in AppleDouble form with forks and metadata intact. This works reliably enough, but it involves a HUGE amount of network activity, and there's issues with making sure that the permissions are correct in the process.
    Is there a way to directly produce the AppleDouble dot-underscore file from a file on an AFP share. Things like SplitForks, RezWhack, etc. don't work on shares. I cannot find any command-line utility, AppleScript extension, Automator action, etc. to do it.

    Thank you. I am aware of that, cpio as well. The problem is that I don't want to have to copy the files, just create the dot-underscore file. For various reasons, we still need to use the Windows-based migration tools to migrate the files. So what I want is something that can read the metadata and resource fork WITHOUT making a copy of the file to produce the dot-underscore file. The solution I
    currently have for them works like tar (without the extra step of storing things in the archive or requirement of using OS X tar to unpack it).

  • How do I run a 10g rep file from the command line, send output to previewer

    Hi Everyone,
    We are migrating from Reports 2.5 to 10g.
    We are creating a batch file to run one of our reports that is in the .rep file format. Can you tell us what we need to put in the batch file to run the report as a paper report and have the reports runtime prompt the user for the login and show the report in the previewer just like in Reports 2.5?
    Thanks.
    Emad

    They should take a look at the "Oracle Application Server - Reports Services - Publishing Reports to the Web" from Application Server Doumentation downloadable from Reports Homepage http://otn.oracle.com/products/reports
    Martin

  • I would like to open an .htm file from the command line using firefox. Firefox responds by trying to open a URL (adding WWW to front of file name)

    firefox is located on unix box and I would like to use it to open report generated. After script creats report I would like to call firefox to read report. "firefox report.htm"

    I have solved this problem. All I needed was to follow firefox with the filename

  • Running class files from the windows command line...

    Hello Everyone,
    My instructor showed us a way to run class files from the windows command line. However every time I try to run the class file from the command line using a command like: java CruiseHelper.class
    I get an error that states "Exception in thread "main" java.lang.NoClassDefFoundError: CruiseHelper/class"

    Hello Everyone,
    My instructor showed us a way to run class files from
    the windows command line. However every time I try
    to run the class file from the command line using a
    command like: java CruiseHelper.class
    I get an error that states "Exception in thread
    "main" java.lang.NoClassDefFoundError:
    CruiseHelper/class"Classes are not file names. You don't have a class named "CruiseHelper.class", that's a file name. The class name is just CruiseHelper (if you have no package statement in it).
    So,
    java -classpath . CruiseHelper

  • Problem with running a java program from the command line

    I have this code:
    package pkg;
    import jxl.*;
    import java.io.File;
    public class TestClass {
         public static void main(String[] args) {
              try{
                   Workbook book = Workbook.getWorkbook(new File("d:/testWorkspace/excFile.xls"));
                   Sheet sheet = book.getSheet(0);
                   String s=sheet.getCell(4, 2).getContents();
                   System.out.println(s);     
              }catch (Exception e){System.err.println(e);}
    }I've wrote it in Eclipse, added jxl.jar to the buildpath, and it works fine.
    Then I tried to run it from the command line and I did it like this:
    D:\testWorkspace\testProject\bin> java -cp \jxl.jar pkg.TestClassThe result was:
    Exception in thread "main" java.lang.NoClassDefFoundError: pkg/TestClass
    Caused by: java.lang.ClassNotFoundException: pkg.TestClass
    ...but the file TestClass.class DOES exist in the folder d:\testWorkspace\testProject\bin\pkg\ and the file jxl.jar IS on the root of drive D (like I already wrote, it worked fine inside the Eclipse).
    So, my question is: How to run this code from the command line?
    I have no idea what went wrong.
    Can someone help me, please?

    The current directory is not implied in the classpath.
    D:\testWorkspace\testProject\bin> java -cp .;d:\ pkg.TestClassor
    D:\testWorkspace\testProject\bin> java -cp .;d:\jxl.jar pkg.TestClassI always forget which is right since I never work with jars...

  • I am unable to run several iMacros from the commnd line concurrently

    The documentation implies that you can run concurrent iMacros by starting Firefox sessions under different profiles. I have tried this, but if I run Firefox from the command line it only takes note of the -P (profile) option if I am also specifying -no-remote (start in a new process). the problem is that to run an iMacro from the command line you have to start a firefox session first, then wait briefly before making the actual firefox call to your iMacro. So I can start a number of separate Firefox sessions under different profiles OK, but when I try to call my iMacros they might go to any of the sessions, and they just end up all hanging.
    If I start my Firefox sessions then go into them manually, I can start the iMacros one iMacro in each and they run fine concurrently.

    Are these newly purchased films or films purchased in the past that you want to re-download ? The 'check for available downloads' will check for things such as pre-orders that haven't been downloaded yet, and (I think) automatic downloads - it doesn't check for things which you've downloaded in the past but which are no longer in your library. If they are past purchases, then depending upon what country that you are in (films can't be re-downloaded in all countries), and whether they are still in the store (film studios occasionally remove them) then they might show under the Purchased link under Quicklinks on the right-hand side of the iTunes store home page on your computer's iTunes for re-downloading.

  • Jar file runs from the command line, but not when I double click it

    Hello, I'm running windows xp. I've created an executable jar file and it runs fine from the command line when I type;
    java -jar wizard.jar
    but, when I double click it . . . nothing.
    Any ideas?

    nothing ? that's weird, windows XP should prompt you to select the program you want to use in order to open Jar files (and give you this silly piece of advice to search the web for the appropriate program)
    you might want to check what program (if any) got associated with .jar extensions :
    in Windows Explorer : Tools => Folder Options => File Types
    hth

  • Running a jar from the command line

    I am trying to run a Jar from the command line. I have a number of classes in a package called "trainnn".
    I put all the classes into a jar
    jar cvf name.jar trainnn\*.classI then creat a file called mainClass.txt with the line (with a blank return line after it, where QueryMatch has the main). This file was placed in the same directory as the package and the jar file
    Main-Class: QueryMatch
    then
    jar cmf mainClass.txt network.jar G:/TrainNN/src/trainnn/QueryMatch.classthis worked fine.....but it is from here I have problems when I try run the jar
    java -jar network.jarbut get this error.
    Exception in thread "main" java.lang.NoClassDefFoundError: QueryMatch
    I cant figure out this error, I have tried specifying the exact path in the mainClass.txt file but that didnt work.
    Any ideas
    Thanks in advance.

    Hi,
    To start a java app in the command line with "java -jar yourJarFile.jar", the jar needs to have a mainfest file "MANIFEST.MF" in a folder called "META-INF". The manifest file would have to contain the name of your starting class, e.g. it could look like thisManifest-Version: 1.0
    Main-Class: com.yourCompany.yourProject.YourClass Hope that helps. Cheers, HJK

  • Help required - running a Java program from the command line

    Hi,
    I have a small non-graphical Java application, packaged into a Jar file. My program relies on classes in another (external) Jar file.
    When I run the application from the IDE, everything works fine. However, when I try to run the application from the command line, I keep getting a NoClassDefFoundError for classes in the external jar.
    Both the application jar file and the external jar file are in my root directory (C:\).
    My command line call is as follows:
    java -cp c:MyExternalLib.jar -jar MyApp.jar
    Any help greatly appreciated.
    Thanks,
    Walter

    hi,
    set classpath=%classpath%;c:\myjar.jar;
    here i have specified myjar.jar file as an example u give ur location.after setting the classpath run ur java application.
    java mypgm
    this will solve ur problem
    regards,
    Ganesh

  • Running a function from a powershell script from the command line

    Rather than creating several scripts each with one function, I have one script with has several functions.... I would like to call the script and select the function i want to use from the command line.
    so far, if i change directory to that of the script i can call the function by doing this:
    cd c:\myscripts
    . .\mytestscript.ps1; myfunction
    this works fine.... i have also tried, what I would like to achieve is calling it like this
    c:\myscripts\mytestscript.ps1; myfunction
    however, i am trying to run this as part of an MDT task sequence, my command line looks like this and using the ; myfunction at the end doesn't work.
    powershell.exe -ExecutionPolicy Bypass %SCRIPTROOT%\CustomScripts\mytestscript.ps1; myfunction
    how can i adapt my command line so that it will successfully call the function within my script?
    thanks
    Steve

    Rename the file from ps1 to psm1 and create a powershell module that contain multiple functions. A module will autoload like the built-in modules.
    Placement of the psm1 file is important for Powershell to find and autoload it.
    The file name and folder name must be the same, for example MyModule.psm1 should be in the folder:
    user\documents\windowspowershell\modules\mymodule
    Windows PowerShell Modules
    http://msdn.microsoft.com/en-us/library/dd878324(v=vs.85).aspx
    PS C:\> get-childItem env:PSModulePath
    Name Value
    PSModulePath C:\Users\User\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

Maybe you are looking for

  • Print text file to  client side printer

    Hi all, I have a character mode report which will print to a client side dot matrix printer in 6i. After converted to 10g, we cannot print to the client side printer (because we don't want to map so many print queue from the AS). So, I try to generat

  • Convertion of String to XML node using Xquery transformation in OSB

    How to convert string to XML node elementusing a built in function using Xquery transformation in OSB?

  • How do I use TC as an external drive?

    I would like to do two things. First, put an iTunes library on the Time Capsule. Second, move important files from a computer to the Time Capsule without losing the ability to access the files from other computers on the network. Trouble is that I ca

  • Blocked invoices BI report

    Hello All, I have a new requirements to create a BI report on blocked invoices.  For a specific date range, users would like to see what are the invoices that were blocked over the date range. The report should be able to capture invoices that were b

  • SQL Server Agent Job is not running as per schedule

    I have a job that is supposed to run every 6 AM.  It was running last week but not this morning.  The big problem is that there are no error messages what so ever. I checked Agent History, SQL server logs and Windows system logs. I checked the schedu