Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Auto Run Java Program


13 replies to this topic

#1 cse-icons

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 351 posts
  • Location:India

Posted 25 October 2004 - 11:48 AM

Some of the installables in java comes in form of .jar file,
one has to just double click or type "java -jar file.jar", and it starts executing.

The reason for this is a line appended in the MANIFEST.MF file of that jar file.

For writing a similar jar file of your own, just write your java file, then compile the same and create a jar file.
Create a MANIFEST.MF file and the content should have the followings:

Manifest-Version: 1.0[br]Created-By: xyz[/br]Main-Class: xyz.MainClass


Here xyz.MainClass is the main class.
Now create a jar file with the manifest file you have created.

jar cvfmM abcd.jar META-INF/MANIFEST.MF .

That's it !!
Double click the jar file and see it running. (provided the jar file association is done)

#2 eldeo

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 19 posts

Posted 07 November 2004 - 12:44 PM

You can also run java program as a windows service. Use javaservice free tool

#3 cse-icons

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 351 posts
  • Location:India

Posted 08 November 2004 - 04:18 AM

hi eldeo,

can you give more specific info regarding the javaservice free tool.
have u tried it?
Is there a similar solution for *nix?

#4 jacksonicson

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 10 posts

Posted 12 November 2004 - 05:00 PM

If you want to run your Programm under Windows, you should try JSmothGen! Its open source and it generates an exe file whitch then locates the JVM in the system and starts teh specific class file which inherits the main method!

#5 cse-icons

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 351 posts
  • Location:India

Posted 13 November 2004 - 11:18 AM

jacksonicson, on Nov 12 2004, 05:00 PM, said:

If you want to run your Programm under Windows, you should try JSmothGen! Its open source and it generates an exe file whitch then locates the JVM in the system and starts teh specific class file which inherits the main method!

<{POST_SNAPBACK}>




Is it spelt "JSmothGen"? I tried to search on google with the same keyword but did not find any matches...
If possible pls give me the website address where I can download the tool.

#6 arunkumarhg

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 13 posts

Posted 29 November 2004 - 06:37 AM

cse-icons, on Nov 13 2004, 05:48 PM, said:

Is it spelt "JSmothGen"? I tried to search on google with the same keyword but did not find any  matches...
If possible pls give me the website address where I can download the tool.

<{POST_SNAPBACK}>


Hi buddy

it not "JSMOOTHGEN" but it is "JSMOOTH" .exe converter of java application for MS windows its an open source project you can get it at "jsmooth.sourceforge.net"
and if you want more information or more tools just give these key words in google you will get lots of links ,

KEY WORDS
1) java application installer
2) Java to exe

what else do you wanna know

Cheers
Arunkumar.H.G

#7 khmerneed

    Cambodian Web & Software Developer.

  • Kontributors
  • PipPipPipPip
  • 59 posts
  • Location:Cambodia
  • Interests:Web Deployment, Visual Source Code,<br />Free Training, Free Source Download.<br />Much more related to web development &amp; software development.

Posted 07 December 2004 - 05:48 AM

Dear Friend!


I am new to java. and i have tried the below problem.
as a usual time i use ms-dos to command java, javac it look like this

c:>\java\bin\javac test.java (this i do a compile for my java file)
c:>\java\bin\java test (this i do a run for my class file)

I wonder if anyway just double click on test.java then it compile for me without going to ms-dos and run javac?

I also wonder if anyway just double cick on test.class then it will run to let me see the work?

I hope everyone may response to these two problems.

Thanks & Best Regards,
Dorei

#8 cse-icons

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 351 posts
  • Location:India

Posted 09 December 2004 - 12:33 PM

Yeah, I think that is possible...

Just right click on .java file and select open with...
from the list select javac.exe (if it exists) or browse to it and select it.
chek the box.. always open with... and there u r....
double click and it should compile...

I have not tried it yet.. but should def work...
similarly for class files.. associate it with java.exe

If these dont work... i suppose u can write a batch file.. which compiles and runs both...

There is sthg u can do in the registry so that in the context menu u get compile and it would compile with javac.exe
wud try out and let u know..

#9 khmerneed

    Cambodian Web & Software Developer.

  • Kontributors
  • PipPipPipPip
  • 59 posts
  • Location:Cambodia
  • Interests:Web Deployment, Visual Source Code,<br />Free Training, Free Source Download.<br />Much more related to web development &amp; software development.

Posted 15 December 2004 - 01:55 AM

Hi,


I have tried so many times, but it is not run that way. when i double click on it, it gone to be open the dos then exit.

I wonder if i have another way.

Thanks & Best Regards,
Dorei

#10 spirit_valley

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 55 posts
  • Location:Hong Kong
  • Interests:Who doesn't like playing games?

Posted 20 December 2004 - 05:19 PM

cse-icons, on Dec 9 2004, 08:33 PM, said:

Yeah, I think that is possible...

Just right click on .java file and select open with...
from the list select javac.exe (if it exists) or browse to it and select it.
chek the box.. always open with... and there u r....
double click and it should compile...

I have not tried it yet.. but should def work...
similarly for class files.. associate it with java.exe

If these dont work... i suppose u can write a batch file.. which compiles and runs both...

There is sthg u can do in the registry so that in the context menu u get compile and it would compile with javac.exe
wud try out and let u know..

<{POST_SNAPBACK}>

I've tried this method...
It's normal when the DOS window open and exit. Once the DOS command finishes the window will be closed automatically.
And in fact I don't recommend this method since you won't be able to read the error messages from the compiler, although you will still be able to compile the program.
Also note that you won't be able to run the program just by "associating it with java.exe". Reason? Do you remember after you compiled the program successfully (e.g. javac testprog.java), what's the command you need to type in order to interpret (execute) the program? It's (javac testprog). You can't include the ".class" when executing the program, or you'll get an error message. And when you associate a file with a program, Windows just append the filename to the end of the program. So when you associate that *.class file to java.exe and you run testprog.class, you will get "java testprog.class" - it won't work. Try it on your own.

khmerneed, on Dec 15 2004, 09:55 AM, said:

Hi,
I have tried so many times, but it is not run that way. when i double click on it, it gone to be open the dos then exit.

I wonder if i have another way.

Thanks & Best Regards,
Dorei

<{POST_SNAPBACK}>

Like cse-icons said, create a batch file to handle the task. But the easiest way may be to simply use an IDE to write and compile the program.


** Edit
Create a batch file to do the task:
Save the following code to runjava.bat under folder C:\j2sdk1.4.2_04\bin
@echo off[br]title Java Compiler[/br]if "%1" == "" goto Help[br]echo Compiling...[/br]javac %1.java[br]if ERRORLEVEL 1 goto Error[/br]echo Compile successful. Running program...[br]java %1[/br]goto End[br]:Help[/br]echo Compiles and run a java program.[br]echo.[/br]echo RUNJAVA [filename][br]echo.[/br]echo   [filename]   File name of the java source code (without .java extension)[br]goto End[/br]:Error[br]echo *** Compile failed ***[/br]:End[br]
[/br]What a long post... ;)




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users