Results 1 to 8 of 8

Thread: How to run a Java application

  1. #1
    Join Date
    Apr 2009
    Beans
    5

    How to run a Java application

    Hi,

    I am trying to run a java application that runs quite happily under windows in Ubuntu (Hardy Heron), to stop having to switch back into windows.

    In windows, it is executed using a batch file that contains:

    @echo off
    java -Xmx500m -cp .;Theme.jar Gui

    I can see thar Theme.jar is a file in the folder, but not Xmx500m

    I have no idea how to get this to run. I have tried ./Theme.jar and get 'insufficient access'. If I try sudo first, I get 'no such file'. Any help would be much appreciated.

    Pete

  2. #2
    Join Date
    Feb 2008
    Location
    St. Petersburg, Russia
    Beans
    116
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to run a Java application

    Try something like
    Code:
    java -jar Theme.jar Gui
    or
    Code:
    java -Xmx500m -cp . -jar Theme.jar Gui
    -Xmx500m, in fact, is not a reference to a file, it allocates 500 Mb of memory for your application.

  3. #3
    Join Date
    Apr 2009
    Beans
    5

    Re: How to run a Java application

    That looks like its getting me closer. I now get "Failed to load Main-Class manifest attribute from Theme.jar".

    Any further suggestions??

    Thanks in advance,

    Pete

  4. #4
    Join Date
    Feb 2008
    Location
    St. Petersburg, Russia
    Beans
    116
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to run a Java application

    Some people seem to have had this problem, and solved it by using Sun's JRE, see e.g. http://getsatisfaction.com/wuala/top...fest_attribute

  5. #5
    Join Date
    Apr 2009
    Beans
    5

    Re: How to run a Java application

    It appears that I am using the Sun JRE.
    This is the result of the alternative configure

    update-alternatives --config java

    There is only 1 program which provides java
    (/usr/lib/jvm/java-6-sun/jre/bin/java). Nothing to configure.

    Having checked the -cp option, I have double checked that I am executing the command in the same directory as the 'Theme.jar'.

    java -Xmx500m -cp . -jar Theme.jar Gui
    Any other ideas would be welcomed?

  6. #6
    Join Date
    May 2009
    Location
    Austin, Texas USA
    Beans
    271
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to run a Java application

    In windows, it is executed using a batch file that contains:

    @echo off
    java -Xmx500m -cp .;Theme.jar Gui
    Yep, it would be executed that way in Windows. However, in Linux the semicolon character is used to separate commands. You can type multiple commands into the terminal all separated by semicolons and they will execute one after the other (with no regard to whether or not the previous command executed successfully, but that's a different topic). Suppose you type the following

    cd ~; ls; cd /; ls

    It should cd into your home directory, then list the files, then cd into the root directory, and then list the files, as if you had typed the four commands separately. So that's the problem. The -cp option to java (classpath) has a semicolon in it which causes the shell to interpret this as 2 separate commands, as if you had typed them separately in the terminal like so:

    Code:
    $ java -Xmx500m -cp .
    $ Theme.jar GUI
    Make sure that the Theme.jar and Gui.class files are both in the same directory, and then change the semicolon to a colon and try to launch the file like this:

    Code:
    java -Xmx500m -cp .:Theme.jar Gui
    It should work. Basically, all it's doing is telling Java to execute the program named Gui with the following options:

    -Xmx500m
    sets the maximum heap size to 500 megabytes

    -cp .:Theme.jar
    tells Java to include some extra files in the classpath, namely, any file that exists in the current directory (referenced by . [dot]) as well as the classes that exist inside of Theme.jar



    This should work...let me know if it doesn't.
    Last edited by gamblor01; May 4th, 2009 at 09:42 PM. Reason: fixing typos

  7. #7
    Join Date
    Apr 2009
    Beans
    5

    Re: How to run a Java application

    Brilliant, you've cracked it. With help from this forum and Ri my resident Ubuntu guru the application is now running.

    Thanks for your help.

    Pete

  8. #8
    Join Date
    May 2009
    Location
    Austin, Texas USA
    Beans
    271
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to run a Java application

    Glad to help. Sorry it took a week to solve this one, but I just joined the forums like 2 or 3 days ago so I answered as quickly as I could.
    If all else fails, use fire.

Bookmarks

Posting Permissions

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