SimpleJava
asked on
starting java application with windows
Hi experts
I have a java application on my notebook.I want this application to start when i boot into windows automatically.
How do i achieve this ? Do i write some kind of batch file ? if so how ?or what are the alternatives?
I have a java application on my notebook.I want this application to start when i boot into windows automatically.
How do i achieve this ? Do i write some kind of batch file ? if so how ?or what are the alternatives?
Or you can just choose a command line of the second line and omit a batch file altogether
ASKER
CEHJ can u clarify the following:
u mean YourApp is my main class file.what if there are other class files that the main class calls?
how do i start the batch file with the Win scheduler ?
u mean YourApp is my main class file.what if there are other class files that the main class calls?
how do i start the batch file with the Win scheduler ?
>>u mean YourApp is my main class file.what if there are other class files that the main class calls?
That doesn't matter. Just imagine you'd typed java X at the command line
>>how do i start the batch file with the Win scheduler ?
Keep it simple at first - omit the batch file
That doesn't matter. Just imagine you'd typed java X at the command line
>>how do i start the batch file with the Win scheduler ?
Keep it simple at first - omit the batch file
Use the 'Scheduled Tasks' applet in Control Panel. Browse to java.exe and be sure to check 'open advanced properties' on the way so you can put in the classpath and class
ASKER
thank you but
>>keep it simple at first-omit the batch file
i dont get it.no batch file, which way then ?
>>keep it simple at first-omit the batch file
i dont get it.no batch file, which way then ?
Not x.bat but java.exe
ASKER
am i getting you. u mean i save the file
java -classpath xxxx YourApp
as java.exe in a notepad or something and then ?
java -classpath xxxx YourApp
as java.exe in a notepad or something and then ?
No. Just browse to java.exe in the Scheduled Apps Control Panel applet. You put the classpath and class in later in the wizard
ASKER
i cant locate the Scheduled Apps Control Panel applet. am on winxp
ASKER
Are you refering to the scheduled task wizard ?
It's actually called Scheduled Tasks, and alternatively you can go to Start > Programs > Accessories > System Tools > Scheduled Tasks..
Although I think it would be easier to create a jar file and just put that in your Programs > Startup folder. A jar file is basically an executable file
Although I think it would be easier to create a jar file and just put that in your Programs > Startup folder. A jar file is basically an executable file
Yes. Sorry i changed the name part way through (see what i said first)
ASKER
Thanks so which one are you advocating ?
A jar file (how to do that) or browsing and locating java.exe and putting the class file in that directory ?
A jar file (how to do that) or browsing and locating java.exe and putting the class file in that directory ?
It's going to be quicker *not* to use a jar file unless you need one anyway
>>... putting the class file in that directory ?
You can leave the class file where it is
>>... putting the class file in that directory ?
You can leave the class file where it is
ASKER
thank you but it seems am not getting u atall.
i thought you said i put the class files in java.exe(which i thought was a directory but cant even locate it now).
let me tell you what i got so far if only am right
1. name java -classpath xxxx YourApp as java.exe
2. put this file in scheduled task
3. windows will then run this task when it starts
am right ? CEHJ
i thought you said i put the class files in java.exe(which i thought was a directory but cant even locate it now).
let me tell you what i got so far if only am right
1. name java -classpath xxxx YourApp as java.exe
2. put this file in scheduled task
3. windows will then run this task when it starts
am right ? CEHJ
>> thought you said i put the class files in java.exe(which i thought was a directory but cant even locate it now).
No, the class file(s) remain(s) in the same place. java.exe is a program, namely the Java interpreter
All you do is browser to java.exe in Scheduled Tasks. Check 'Open advanced properties ...' and put the classpath and class in
No, the class file(s) remain(s) in the same place. java.exe is a program, namely the Java interpreter
All you do is browser to java.exe in Scheduled Tasks. Check 'Open advanced properties ...' and put the classpath and class in
ASKER
to be honest you are not clear to me
>>All you do is browser to java.exe in Scheduled Tasks. Check 'Open advanced properties ...' and put the classpath and class in
ur sentence seems not to be completed. where do i put the classpath and the class ?
to make things worse i cant locate the program java.exe
>>All you do is browser to java.exe in Scheduled Tasks. Check 'Open advanced properties ...' and put the classpath and class in
ur sentence seems not to be completed. where do i put the classpath and the class ?
to make things worse i cant locate the program java.exe
>>ur sentence seems not to be completed. where do i put the classpath and the class ?
It is complete, but 'browser' should be 'browse'
I'll look for the caption of the box where you put it - hang on...
>>to make things worse i cant locate the program java.exe
That's where it's been installed. If you do
echo %PATH%
at the command line you should see it (or its bin directory) in there
It is complete, but 'browser' should be 'browse'
I'll look for the caption of the box where you put it - hang on...
>>to make things worse i cant locate the program java.exe
That's where it's been installed. If you do
echo %PATH%
at the command line you should see it (or its bin directory) in there
It's in the box marked 'Run:'
You put the classpath and path after the command, which in my case is:
"C:\Program Files\Java\jre1.5.0_02\bin \java.exe"
or you could have
"C:\Program Files\Java\jre1.5.0_02\bin \javaw.exe "
So that would be
"C:\Program Files\Java\jre1.5.0_02\bin \java.exe" -classpath xxxx YourApp
You put the classpath and path after the command, which in my case is:
"C:\Program Files\Java\jre1.5.0_02\bin
or you could have
"C:\Program Files\Java\jre1.5.0_02\bin
So that would be
"C:\Program Files\Java\jre1.5.0_02\bin
ASKER
Thank you. i was looking for the .exe extension
i'll be back in a minute
i'll be back in a minute
Windows stupidly hides file extensions by default so you may need to make them visible
ASKER
i'm running into some problems with windows.i am getting the following warnings:
the task name cannot contain the characters :,\,/,<,> etc
this is what i have in the text field of the scheduled task wizard
java -classpath C:\Programs\Users\Joe\mark Values
where markValues is the main class
what is wrong ?
the task name cannot contain the characters :,\,/,<,> etc
this is what i have in the text field of the scheduled task wizard
java -classpath C:\Programs\Users\Joe\mark
where markValues is the main class
what is wrong ?
No, you should have something more like:
"C:\Program Files\Java\jre1.5.0_02\bin \java.exe" -classpath C:\Programs\Users\Joe markValues
in the Run: box
"C:\Program Files\Java\jre1.5.0_02\bin
in the Run: box
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
but if i put it in the run box how show will i be that windows will open the program anytime i start my notebook?
Why not test it?
ASKER
Thanks a lot. i will test all possible solutions and let you know.
Keep tight.
Keep tight.
ASKER
i put the lines
@echo off
"C:\Program Files\Java\jre1.5.0_02\bin \java.exe" -classpath C:\Programs\Users\Joe markValues
in a notepad saved as mark.bat.
i restart my computer and the java application is not started.the command prompt pops up and exits without the application showing up.
@echo off
"C:\Program Files\Java\jre1.5.0_02\bin
in a notepad saved as mark.bat.
i restart my computer and the java application is not started.the command prompt pops up and exits without the application showing up.
ASKER
when i pause the batch file i get the error exception in thread "main" java.lang.NoClassDefFoundE rror
That suggests your classpath's wrong
ASKER
this error occurs only with the lines
@echo off
"C:\Program Files\Java\jre1.5.0_02\bin \java.exe" -classpath C:\Programs\Users\Joe\mark Values
but if i put the lines
@echo off
java -classpath "C:\Program\Users\Joe\mark Values"
the application which is a gui is loaded alright with the exception that images(.jpg) are not loaded at all.
am i reaching you?
@echo off
"C:\Program Files\Java\jre1.5.0_02\bin
but if i put the lines
@echo off
java -classpath "C:\Program\Users\Joe\mark
the application which is a gui is loaded alright with the exception that images(.jpg) are not loaded at all.
am i reaching you?
Yes, you of course need to put in the correct path to *your* java.exe, or none at all (as long as it's on your path - and it is)
>> ...images(.jpg) are not loaded at all.
How are your images loaded in your app?
>> ...images(.jpg) are not loaded at all.
How are your images loaded in your app?
ASKER
i do with the following code
Box box=Box.createHorizontalBo x();
c.insets=new Insets(8,8,8,8);
box.add(new JLabel(new ImageIcon("my.gif")));
....
.....
panel.add(box,c);
Box box=Box.createHorizontalBo
c.insets=new Insets(8,8,8,8);
box.add(new JLabel(new ImageIcon("my.gif")));
....
.....
panel.add(box,c);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much.works fine but one more problem with a driver.
There is the error i get with java.sql.SQLException:java .lang.Clas sNotFoundE xception: com.mysql.jdbc.Driver
this does not happen when i do java markValues at the command prompt but only with the batch. how do i resolve this ?
There is the error i get with java.sql.SQLException:java
this does not happen when i do java markValues at the command prompt but only with the batch. how do i resolve this ?
You need to put the driver jar in the classpath too. That includes the file and extension
ASKER
maybe i'm not able to set the classpath correctly.i however solve the problem by copying the mysql com directory with all its contents and putting it in the directory that holds my main class files.
This works perfectly fine.
CEHJ do u have any idea of avoiding the poping up of the command window ?
This works perfectly fine.
CEHJ do u have any idea of avoiding the poping up of the command window ?
>>i however solve the problem by copying the mysql com directory with all its contents and putting it in the directory that holds my main class files.
That's an unfortunate way of solving it ;-)
>> maybe i'm not able to set the classpath correctly
Possibly. What did you give as the classpath?
>>CEHJ do u have any idea of avoiding the poping up of the command window ?
Run javaw.exe instead of java.exe
That's an unfortunate way of solving it ;-)
>> maybe i'm not able to set the classpath correctly
Possibly. What did you give as the classpath?
>>CEHJ do u have any idea of avoiding the poping up of the command window ?
Run javaw.exe instead of java.exe
ASKER
classpath: C:\mysqljconnect\mysql-con nector-jav a-3.1.7\my sql-connec tor-java-3 .1.7-bin.j ar
ASKER
i tried javaw.exe but still have the command window poping up.
>> classpath: C:\mysqljconnect\mysql-con nector-jav a-3.1.7\my sql-connec tor-java-3 .1.7-bin.j ar
That should be *part* of the classpath, not the whole of it. Your own class should also be part of it
>> i tried javaw.exe but still have the command window poping up.
Do you have anything asking for input or otherwise pausing execution?
That should be *part* of the classpath, not the whole of it. Your own class should also be part of it
>> i tried javaw.exe but still have the command window poping up.
Do you have anything asking for input or otherwise pausing execution?
ASKER
>> That should be part of the classpath,.... Your own class should also be part
my own class --- which ones (the ones i'm running ?)
am setting the classpath as an environmental variable
>> Do you have anything asking for input or ....
the command window is blank. nothing seen
my own class --- which ones (the ones i'm running ?)
am setting the classpath as an environmental variable
>> Do you have anything asking for input or ....
the command window is blank. nothing seen
>>am setting the classpath as an environmental variable
Your classpath (in the startup) should be at least:
-classpath C:\mysqljconnect\mysql-con nector-jav a-3.1.7\my sql-connec tor-java-3 .1.7-bin.j ar
;C:\Programs\Users\Joe\mar kValues
but if it gets much longer, then you'd be better putting it in a batch file
Your classpath (in the startup) should be at least:
-classpath C:\mysqljconnect\mysql-con
;C:\Programs\Users\Joe\mar
but if it gets much longer, then you'd be better putting it in a batch file
ASKER
but what is wrong if i set the connector as an environment variable since java bin classpath is already set as an environmental variable
>> but what is wrong if i set the connector as an environment variable
Nothing, as long as you put all the classpath in:
http://mindprod.com/jgloss/classpath.html
>>since java bin classpath is already set as an environmental variable
The java bin directory is nothing to do with the classpath (see above link)
Nothing, as long as you put all the classpath in:
http://mindprod.com/jgloss/classpath.html
>>since java bin classpath is already set as an environmental variable
The java bin directory is nothing to do with the classpath (see above link)
ASKER
Thank you for the information.Useful i guess i will manage.
Any info on the poping up of the command window?
Any info on the poping up of the command window?
ASKER
o.k manage to solve the pop up of the command window problem.
thanks for ur help
thanks for ur help
ASKER
thanks CEHJ
OK :-) What was it with the popping up?
ASKER
sorry i've been away.
the problem i imagined was a way to close the batch window after executing the command. it ges like this
START java -classpath xxxx myclass
EXIT
everything works fine.
the problem i imagined was a way to close the batch window after executing the command. it ges like this
START java -classpath xxxx myclass
EXIT
everything works fine.
@echo off
java -classpath xxxx YourApp