win xp not opening class file.

win xp not opening class file.Runtime.getRuntime().exec("cmd /C start c:/database/Myclass.class"); orRuntime.getRuntime().exec("cmd /C c:/database/Myclass.class"); is this code wrong for xp ?
[226 byte] By [intelchip] at [2007-9-30 22:26:50]
# 1
whats the correct syntax to run class file in XP ?
intelchip at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 2
java -classpath c:\some\path some.package.SomeClass
atmguy at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 3

That code is wrong for all OSes. You don't run the .class file, you run the java executable, passing the class with the main(...) in it:

"cmd /C start java.exe c:/database/Myclass"

Is closer to being correct, if the java executable is in the path, and your Myclass is not in a package. If that fails, you might want to test

"cmd /C start java.exe c:\\database\\Myclass"

And if that fails, you chould play around on the console until you get it to work, then copy the command you used.

stevejluke at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 4

Hi,

I guess you want to run the class files instead of opening them.

Try to include java in the command line parameters that you are asking your Runtime to execute.

But I did not understand why do you want runtime to execute a class file when java itself can do that for you.

If it was some windows executable that you want to run it would have been okay.

Aviroop

aviroop at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 5

let me give some more information...

i have c:\database

in this folder i have 2 class...Myclass.class and Dbconnection.class

Myclass simply uses the database connection from Dbconnection.class , nothing else.

you see both of the classes are in the same folder(i.e c:\database) and there is no package

statement inside the code .

in command prompt if i do....

c:\database\java Myclass//this works fine

but i want this class to run at runtime, so i did like above and it is not running!!

what i am getting is a irritating windows file chooser is poping up and saying "class not

found...browse or search in web...etc etc"

Now my question is >

Q1 .how can i run that class at runtime ?

N.B

-

here is some brief idea abt classes

Dbconnection.java

--

{

DriverManager.forClass("...database....");

// only for database connection

}

Myclass.java

-

{

.....

Connection con =db.getConnection();

//use this con and show results for ur database related queries.

}

Q2. Can u plz tell those correct syntax how to run class file in this situation ?

i will try all possible solutions tomorrow.

thanx.

intelchip at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 6

>>But I did not understand why do you want runtime to execute a class file when java itself can do that for you

bcoz it is my requirement................................however ,infact i am checking a condition at runtime . if that condition is true then i want to run that class file at runtime

intelchip at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 7
Replies 2 & 3 still apply. You run the VM (java.exe), NOT the class file. The line that you say works is doing exactly that--c:\database\java Myclass runs the VM, not the class.
jverd at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 8

> >>But I did not understand why do you want runtime to

> execute a class file when java itself can do that for

> you

>

>

> bcoz it is my

> requirement.

Can't do it. Class files are not executable by Windows. You have to invoke a VM (usually java.exe) and give it the class as an argument.

jverd at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 9

> bcoz it is my

> requirement................................

I guess you are not in the business of writing programs for clients, but if you ever do that, you should know that there are times that you have to (politely) tell the client that their requirement is probably stupid, and that there may well be a much simpler way to do that.

DrClap at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 10
actually this would be just an integrated system....NOT client-server at all.i have created several threads......when all those threds will complete their task i will call those 2 class at run time and to populate the database.it would be a stand alone program.thanx
intelchip at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 11

> actually this would be just an integrated

> system....NOT client-server at all.

>

> i have created several threads......when all those

> threds will complete their task i will call those 2

> class at run time and to populate the database.

>

> it would be a stand alone program.

Huh?

What does this have to do with anything?

jverd at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 12
How can one be so advanced to know about Threads and at the same time so clueless not to know how to run a Java program?
CeciNEstPasUnProgrammeur at 2007-7-7 12:50:04 > top of Java-index,Java Essentials,Java Programming...
# 13

But really, why do you want to run this other class in its own VM? There are valid reasons for doing so in some situations, but it adds complexity and overhead, so I would avoid it if I could. Just saying, "because it's my requirement," is not a particularly good answer. You're free not to tell us if you want, but I'd think if somebody was trying to help you improve your program you would answer their questions.

jverd at 2007-7-7 12:50:05 > top of Java-index,Java Essentials,Java Programming...
# 14
it is hanging......how to use class loader to run this class?
intelchip at 2007-7-7 12:50:05 > top of Java-index,Java Essentials,Java Programming...
# 15
i browsed api,but could not understand the syantax to use classloader
intelchipa at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...
# 16

> i browsed api,but could not understand the syantax to

> use classloader

did you take a look over the tutorials?

[url http://java.sun.com/developer/onlineTraining/Security/Fundamentals/index.html] Fundamentals of Java Security by MageLang Institute Release Java 2

This short course covers the new security features including writing a class loader and granting access permissions to programs.

mlka at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...
# 17
> i browsed api,but could not understand the syantax to> use classloaderIndeed. I wouldn't expect that merely "browsing" the API would be sufficient to confer an understanding of classloaders on an inexperienced Java programmer.
jverda at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...
# 18

hi....i have managed to run it....those 2 classes was given to me by my friend. so did not want to change that except running it at runtime.

i changed little bit(created package) in those files.

and created a object in my application and called its method....that's it......

but why why runtime exec() do not work ?

i am fed up with runtime exce() command...... despite giving correct syntax (as provided)it proves nothing except hanging.

so i took alternative way to run. its fine now and working

thanx all

intelchipa at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...
# 19

> but why why runtime exec() do not work ?

> i am fed up with runtime exce() command...... despite

> giving correct syntax (as provided)it proves nothing

> except hanging.

It does work, it might just not work as you expect it to do. Runtime.exec() has to be used thoughtfully and cautiously, to say the least.

CeciNEstPasUnProgrammeura at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...
# 20

>

> but why why runtime exec() do not work ?

> i am fed up with runtime exce() command...... despite

> giving correct syntax (as provided)it proves nothing

> except hanging.

So you did actually put the VM executable in there, instead of trying to run the class file?

You might want to look at this:

[url=http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]Navigate yourself around pitfalls related to the Runtime.exec() method[/url]

jverda at 2007-7-20 1:03:52 > top of Java-index,Java Essentials,Java Programming...