• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting .class to .com

 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would I take an xyz.class file containing a proper main() method and create an xyz.com file that could be called on the command line by simply typing "xyz" ?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I know, .com files are rarely used any more except for specific system tasks. .exe files are much more common for several technical reasons, however this probably isn't the place to go into such a discussion.

There are some other tricks to make a single executable that will run your Java program. Although, for a single file with a single class, it probably isn't worth it. The trick I have begun to use lately is to create a JAR file (using the jar utility) that contains all the .class files that I compile from my source code. You need to make a manifest file with the "Main-Class" attribute set to the class that should be run from this jar file.

Once the jar is created, you can run it by typing

In Windows, you can also execute the jar file by double-clicking it in Windows Explorer.

There are also compilers available that compile your Java program into an executable, but I am not familiar with them. The main draw back is that the compiled program looses Java's cross-platform capabilities. On the other hand, the jar file I described above can usually run as-is on any machine with a JVM installed.

HTH

Layne
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
p.s. You may also want to use the Search tool (see the link at the top of the page) to find previous messages discussing this topic. You can start with "stand alone executable" and see what you can find.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For creating an executable JAR, you might like to take a look at the "Creating an Executable JAR" thread.

For creating an exe, I recommend trying a quick search on this and the intermediate forums for "java exe".

If you go the exe route, please report back and let us know how things went. Of course, if you run into a problem, don't hesitate to post a question about it. I'd recommend the intermediate forum for such a conversation.
[ September 19, 2004: Message edited by: Dirk Schreckmann ]
reply
    Bookmark Topic Watch Topic
  • New Topic