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?
SimpleJavaAsked:
Who is Participating?
 
CEHJCommented:
But at this rate it may be quicker to save the following as a batch file and put it into your startup folder:


@echo off
"C:\Program Files\Java\jre1.5.0_02\bin\java.exe" -classpath C:\Programs\Users\Joe  markValues
0
 
CEHJCommented:
Yes you can start the batch file with the Win scheduler. Set it to run at startup

@echo off
java -classpath xxxx YourApp
0
 
CEHJCommented:
Or you can just choose a command line of the second line and omit a batch file altogether
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
SimpleJavaAuthor Commented:
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 ?
0
 
CEHJCommented:
>>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
0
 
CEHJCommented:
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
0
 
SimpleJavaAuthor Commented:
thank you but
>>keep it simple at first-omit the batch file
i dont get it.no batch file, which way then ?
0
 
CEHJCommented:
Not x.bat but java.exe
0
 
SimpleJavaAuthor Commented:
am i getting you. u mean i save the file

java -classpath xxxx YourApp

as java.exe in a notepad or something and then ?
0
 
CEHJCommented:
No. Just browse to java.exe in the Scheduled Apps Control Panel applet. You put the classpath and class in later in the wizard
0
 
SimpleJavaAuthor Commented:
i cant locate the Scheduled Apps Control Panel applet. am on winxp
0
 
SimpleJavaAuthor Commented:
Are you refering to the scheduled task wizard ?
0
 
mgcITCommented:
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
0
 
CEHJCommented:
Yes. Sorry i changed the name part way through (see what i said first)
0
 
SimpleJavaAuthor Commented:
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 ?
0
 
CEHJCommented:
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
0
 
SimpleJavaAuthor Commented:
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
0
 
CEHJCommented:
>> 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
0
 
SimpleJavaAuthor Commented:
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
0
 
CEHJCommented:
>>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
0
 
CEHJCommented:
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
0
 
SimpleJavaAuthor Commented:
Thank you. i was looking for the .exe extension
i'll be back in a minute
0
 
CEHJCommented:
Windows stupidly hides file extensions by default so you may need to make them visible
0
 
SimpleJavaAuthor Commented:
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\markValues

where markValues is the main class
what is wrong ?
0
 
CEHJCommented:
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
0
 
SimpleJavaAuthor Commented:
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?
0
 
CEHJCommented:
Why not test it?
0
 
SimpleJavaAuthor Commented:
Thanks a lot. i will test all possible solutions and let you know.
Keep tight.
0
 
SimpleJavaAuthor Commented:
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.
0
 
SimpleJavaAuthor Commented:
when i pause the batch file i get the error exception in thread "main" java.lang.NoClassDefFoundError
0
 
CEHJCommented:
That suggests your classpath's wrong
0
 
SimpleJavaAuthor Commented:
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\markValues

but if i put the lines
@echo off
java -classpath "C:\Program\Users\Joe\markValues"

the application which is a gui is loaded alright with the exception that images(.jpg) are not loaded at all.
am i reaching you?
0
 
CEHJCommented:
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?
0
 
SimpleJavaAuthor Commented:
i do with the following code
Box box=Box.createHorizontalBox();
c.insets=new Insets(8,8,8,8);
box.add(new JLabel(new ImageIcon("my.gif")));
....
.....
panel.add(box,c);
0
 
CEHJCommented:
Try


box.add(new JLabel(new ImageIcon(getClass().getResource("my.gif"))));
0
 
SimpleJavaAuthor Commented:
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.ClassNotFoundException: 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 ?
0
 
CEHJCommented:
You need to put the driver jar in the classpath too. That includes the file and extension
0
 
SimpleJavaAuthor Commented:
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 ?
0
 
CEHJCommented:
>>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



0
 
SimpleJavaAuthor Commented:
classpath:   C:\mysqljconnect\mysql-connector-java-3.1.7\mysql-connector-java-3.1.7-bin.jar
0
 
SimpleJavaAuthor Commented:
i tried javaw.exe but still have the command window poping up.
0
 
CEHJCommented:
>> classpath:   C:\mysqljconnect\mysql-connector-java-3.1.7\mysql-connector-java-3.1.7-bin.jar

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?
0
 
SimpleJavaAuthor Commented:
>> 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
0
 
CEHJCommented:
>>am  setting the classpath as an environmental variable

Your classpath (in the startup) should be at least:

-classpath  C:\mysqljconnect\mysql-connector-java-3.1.7\mysql-connector-java-3.1.7-bin.jar
;C:\Programs\Users\Joe\markValues

but if it gets much longer, then you'd be better putting it in a batch file
0
 
SimpleJavaAuthor Commented:
but what is wrong if i set the connector as an environment variable since java bin classpath is already set as an environmental variable
0
 
CEHJCommented:
>> 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)

0
 
SimpleJavaAuthor Commented:
Thank you for the information.Useful i guess i will manage.
Any info on the poping up of the command window?
0
 
SimpleJavaAuthor Commented:
o.k manage to solve the pop up of the command window problem.
thanks for ur help
0
 
SimpleJavaAuthor Commented:
thanks CEHJ
0
 
CEHJCommented:
OK :-) What was it with the popping up?
0
 
SimpleJavaAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.