Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting .class to .com

 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • 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" ?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic