Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
Like Tree5Likes

Thread: Running Programs through Java

  1. #21
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Running Programs through Java

    Norm and gimbal2 are exactly right. There are far more devious and undetectable ways to hack a system once it has been broken into. E.g., one of the system binaries can be replaced with a malicious version, or a {gasp} rootkit may be installed. They both can be done even with the default PATH setting.

    Norm is also spot-on with regards to executable search time and PATH entry order. PATH (variable) - Wikipedia, the free encyclopedia has a short description on this,
    When a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches the current working directory and then searches the path, examining each directory from left to right, looking for an executable filename that matches the command name given.
    [...]
    If used unwisely, however, the value of the PATH variable can slow down the operating system by searching too many locations, or invalid locations.
    This is one of "how many is too many." PATH is there to be used, and it can be abused. Hence "it doesn't matter much" in the context of non-executable files (not) being executed, and as long as it is not abused by putting in every imaginable directory containing executables.

    Now why can't I simply type "java openClass" in my cmd without having to cd to the actual location?
    PATH is used for the executable that that is at the start of the command line. In the above case, it is "java". It is not applied to command parameters, and so the OS will not search through directories in PATH for "openClass". If you think about it, "openClass" can refer to a file, a literal string, a switch, etc. There's no way the OS can know what "openClass" is in relation to "java".
    AlexGraal likes this.

  2. #22
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    175
    Rep Power
    0

    Default Re: Running Programs through Java

    Ah. I see.

    So what are my options then?

    I've written a program that keeps a log of which classes I'm working on and when, and also opens all of the programs I need to work on each class, along with online resources.I don't want to have to CD to it every time. How can I run my java program by simply typing "openClass" or something like that


    EDIT:

    So, a simple 2 minute search yielded this find:

    Simply create a .bat file with the following lines in it:

    @ECHO OFF
    set CLASSPATH=.
    set CLASSPATH=%CLASSPATH%;path/to/needed/jars/my.jar

    %JAVA_HOME%\bin\java -Xms128m -Xmx384m -Xnoclassgc ro.my.class.MyClass
    Posted here by a user called demonstene.

    Is this the correct way of doing this, how does this work, and why does it work? Furthermore, where is the "name" of the "function" actually defined?
    Last edited by AlexGraal; 03-31-2014 at 05:21 PM.

  3. #23
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Running Programs through Java

    The program you run by 'not CDing' is java; that works, you can run java.exe from wherever you want. What you are really asking is: how can I tell the Java runtime to run a specific class without having to specify a full path to it.

    And the answers are:

    a) by setting a proper CLASSPATH (which means learning how to work with the CLASSPATH).
    b) creating a batch file which invokes the proper java command for you and put that batch file in a folder which is on the PATH

    Probably even applying both solutions.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #24
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Running Programs through Java

    How can I run my java program by simply typing "openClass" or something like that
    Make a batch file and put it in a folder that is on the PATH.
    Another useful tailoring feature for batch files is the use of Environment variables.
    Some sample batch files I use:

    @REM Execute a java class file
    java.exe %~n1
    MORE
    @Rem Copy arg to clipboard
    @java -jar D:\JavaDevelopment\runtime\CopyToCB.jar "%1"
    @rem pause
    @REM Check classpath to a class file
    @ECHO OFF
    @java.exe -jar D:\JavaDevelopment\CkClasspath.jar -CP "%CLASSPATH%" %1 %2 %3
    @ECHO ON
    REM Close window when Finished
    @REM Start the ShowClassInfo program
    @ECHO ON
    ECHO %1
    java.exe -cp %JAVA_RUN%\ShowClassInfo.jar;.;..\ NormsTools.ShowClassInfoApp %1 %2 %3
    @ECHO ON
    REM Close window when Finished
    MORE
    These are all in a folder that is on PATH.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Running Programs through Java

    Do you use Eclipse? If you do, Eclipse + Mylin might be a good fit for your purposes.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 7
    Last Post: 09-21-2012, 01:47 PM
  2. Running Java programs in windows 7
    By jonytek in forum New To Java
    Replies: 1
    Last Post: 02-09-2011, 04:45 AM
  3. Replies: 6
    Last Post: 04-20-2009, 04:34 AM
  4. Running 3 Java programs in sequence.
    By loktamu in forum New To Java
    Replies: 2
    Last Post: 11-23-2008, 06:50 PM
  5. Problem in running java programs
    By aravind in forum New To Java
    Replies: 0
    Last Post: 07-14-2008, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •