Running program independent of Compiler

Hi,

I just finished a large java program and want to run it on other people's windows machines independently of the compiler I'm using. Can someone tell me (or tell me a tutorial that tells me) how to do this. I think it involves batch files, but I've no experience with them.

Until now I've just used the "build & run" option from my Netbeans compiler.

Any takers?

[399 byte] By [LemonLiona] at [2007-11-26 23:00:23]
# 1
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.htmlThe short version is java -cp . MyClassIf that doesn't work, go through the above tutorial.
jverda at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 2
What you want is a jar file. Google or search Sun's website.
floundera at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 3
Cheers, I'll look at the tutorial tomorrow
LemonLiona at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 4
Also http://java.sun.com/docs/books/tutorial/deployment/jar/
deepravea at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 5

I've tried everything in the tutorial on running programs from the command line. I can't get anything working from a batch file or direct from command line. I get an error (Exception in thread "main" java.lang.NoClassDefFoundError: Client) and the tutorial says you might be able to fix be using "set CLASSPATH=" but that didn't help.

I don't see how jar files will help me, all they are are collection files. What I need is a way of running a java program independent of a compiler. I tried making a jar file using the jar command that they said in the jar tutorial but that didn't work either (maybe they meant it for unix?)

Anyway, still got the same problem...

LemonLiona at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 6

Looks like the jvm cannot find your class files.

Please make sure the Client class in is in your classpath. If it then still does not work pelase provide the following information:

Your current classpath

The java command you are using (i.e java -cp. Client )

The directory you are running the java command from

The directory containing your client class.

Lima

LimaBravoa at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 7

> I've tried everything in the tutorial on running

> programs from the command line. I can't get anything

> working from a batch file or direct from command

> line. I get an error (Exception in thread "main"

> java.lang.NoClassDefFoundError: Client) and the

> tutorial says you might be able to fix be using "set

> CLASSPATH=" but that didn't help.

>

> I don't see how jar files will help me, all they are

> are collection files. What I need is a way of

> running a java program independent of a compiler. I

> tried making a jar file using the jar command that

> they said in the jar tutorial but that didn't work

> either (maybe they meant it for unix?)

>

> Anyway, still got the same problem...

you can't have followed the tutorial properly, then. it definately works. this is just another example of why IDEs are a bad idea for inexperienced coders. it shields them from too many important problems such as this. using the CLASSPATH environment variable isn't a particularly good idea, either. and no, jars are not unix-specific

what exactly is it you're doing? I mean, what are you doing to run your code that isn't working?

georgemca at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 8

I'm running windows command prompt. I'm going to the directory which my *.class files are in. I'm checking that they're are in there with dir function. They are there. I am inputing "java Client". I receive an error. Here is what I'm getting:

C:\Documents and Settings\Jim Heart\Collab\build>cd classes

C:\Documents and Settings\Jim Heart\Collab\build\classes>dir

Volume in drive C is Partition_1

Volume Serial Number is EC74-E3ED

Directory of C:\Documents and Settings\Jim Heart\Collab\build\classes

27/03/2007 06:12<DIR> .

27/03/2007 06:12<DIR> ..

27/03/2007 07:02 6,281 Client.class

27/03/2007 04:34663 Client.class.jsmooth

27/03/2007 05:54 1,363 ClientThread.class

27/03/2007 06:26705 CollabFrame$1.class

27/03/2007 06:26707 CollabFrame$10.class

27/03/2007 06:26708 CollabFrame$11.class

27/03/2007 06:26708 CollabFrame$12.class

27/03/2007 06:26705 CollabFrame$2.class

27/03/2007 06:26705 CollabFrame$3.class

27/03/2007 06:26705 CollabFrame$4.class

27/03/2007 06:26705 CollabFrame$5.class

27/03/2007 06:26705 CollabFrame$6.class

27/03/2007 06:26705 CollabFrame$7.class

27/03/2007 06:26705 CollabFrame$8.class

27/03/2007 06:26705 CollabFrame$9.class

27/03/2007 06:2616,921 CollabFrame.class

23/03/2007 01:25747 CollConnectDialog$1.class

23/03/2007 01:25747 CollConnectDialog$2.class

23/03/2007 01:25 4,302 CollConnectDialog.class

27/03/2007 07:02733 CollServerFrame$1.class

27/03/2007 07:02733 CollServerFrame$2.class

27/03/2007 07:02733 CollServerFrame$3.class

27/03/2007 07:02 6,502 CollServerFrame.class

27/03/2007 05:54 1,438 DocUpdater.class

27/03/2007 01:34677 JDialog$1.class

27/03/2007 01:34566 JDialog$2.class

27/03/2007 01:34 2,837 JDialog.class

27/03/2007 03:4123 run.bat

27/03/2007 07:02 2,877 Server.class

27/03/2007 07:02 5,861 ServerThread.class

23/03/2007 01:29 1,141 ServerThreadList.class

31 File(s) 63,613 bytes

2 Dir(s) 15,247,794,176 bytes free

C:\Documents and Settings\Jim Heart\Collab\build\classes>java Client

Exception in thread "main" java.lang.NoClassDefFoundError: org/jdesktop/layout/G

roupLayout$Group

at Client.<init>(Client.java:45)

at Client.main(Client.java:344)

C:\Documents and Settings\Jim Heart\Collab\build\classes>

--

And in response to georgmc, I did follow the tutorial as it said. If you think I didn't, please point out where. And I wasn't suggesting that Jar's are unix specific, merely that the ways of producing them in the tutorial supplied might have been. My end goal is to produce a file which can be double clicked on by an ordinary user, which will run my java program. However, presumably before I get to that stage, I need to be successful in getting it to run from the command line directly. I have not been able to achieve that and I have no idea why. (My program runs fine in Netbeans)

Hope one of you can help, I remember in 2nd year university we had a similar problem getting windows machines to do this, including the lecturer, which probably explains why I'm having so much trouble...

LemonLion

LemonLiona at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 9
Oh, and I don't know my current classpath Lima. How do I find out?
LemonLiona at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 10

The jvm is telling you it cannot find the class org/jdesktop/layout/G

roupLayout.

Since org.jdesktop isn't part of the default jvm you will need to make sure the class (and all opther classes needed by jdesktop) are in your classpath. I'm not familiar with jdesktop but my guess will be you have a jarfile of the jdesktop classes somewhere (it might even have come with your ide). So you'll need to find that jar and include it in your classpath.

Lima

LimaBravoa at 2007-7-10 13:06:30 > top of Java-index,Java Essentials,Java Programming...
# 11

you haven't specified a classpath for executing the code. are you relying on the environment variable CLASSPATH? don't, it's a bad practice that leads to all sorts of problems. you need to specify that jdesktop jar on your classpath. something like

java -cp .;c:\libdir\jdesktop.jar Client

note I'm making up the filenames and paths etc. you should be able to fill it in yourself. get in the habit of being very specific about what the classpath should be for each project, and you'll avoid all sorts of problems. another good idea is to have a lib directory per project, where you put all the third-party jars like jdesktop

georgemca at 2007-7-10 13:06:31 > top of Java-index,Java Essentials,Java Programming...
# 12

Well its best not to rely on the classpath of the system anyhow, so ignore the lookup for now. Just give your own classpath wth your java command as explained in

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html

(make sure to also include . (a dot) for the current directory and then add the jar containing your jdesktop files

[edit]

Yeah as georgemc also said :)

[/edit]

Lima

LimaBravoa at 2007-7-10 13:06:31 > top of Java-index,Java Essentials,Java Programming...