„Google“ grupės nebepalaiko naujų „Usenet“ įrašų ar prenumeratų. Istorinį turinį galima peržiūrėti.

Problems with javac and java

2 peržiūros
Praleisti ir pereiti prie pirmo neskaityto pranešimo

Will Critchlow

neskaityta,
2000-08-20 03:00:002000-08-20
kam:
I have written a few little programs in Borland's JBuilder 3.

They compile and run with no problems from within JBuilder but I can't
compile them with javac and they won't run using java.exe.

When I try to compile, a typical error message is:
share.java:11: Class share.Frame1 not found.
Frame1 frame = new Frame1();

However, Frame1.java is in the same directory as share.java and I haven't
set classpath.

What am I doing wrong?

If instead, I try to run the class files produced by JBuilder, I get error
messages similar to:
Exception in thread "main" java.lang.NoClassDefFoundError: share (wrong
name: sh
are/share)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:403)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:10
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
at java.lang.ClassLoader.loadClass(ClassLoader.java:237)


Can someone help?

Thanks

W

Margalit Gur-Arie_elidan1

neskaityta,
2000-08-20 03:00:002000-08-20
kam:
Will Critchlow wrote:
>
> I have written a few little programs in Borland's JBuilder 3.
>
> They compile and run with no problems from within JBuilder but I can't
> compile them with javac and they won't run using java.exe.
>
> When I try to compile, a typical error message is:
> share.java:11: Class share.Frame1 not found.
> Frame1 frame = new Frame1();
>


This message tells you that Frame1 is not found in package share, where
the similarly named, class share resides.


> However, Frame1.java is in the same directory as share.java and I haven't
> set classpath.
>
> What am I doing wrong?
>
> If instead, I try to run the class files produced by JBuilder, I get error
> messages similar to:
> Exception in thread "main" java.lang.NoClassDefFoundError: share (wrong
> name: sh
> are/share)


This one tells you ,it couldn't find *share* in the default package of
the current directory, as requested, but it did find some *share* file
in a package named *share*.

From the error messages you are getting, it looks like the *share* class
is in a package named *share* also, while Frame1 is not. Take a look at
the package declarations in those files, and either put them all in the
same package or use fully qualified class names, or use imports.

Wong Kam Chuen

neskaityta,
2000-08-20 14:14:202000-08-20
kam:

Will Critchlow <wan...@currantbun.com> wrote in message
news:39a0...@news.telinco.net...

> I have written a few little programs in Borland's JBuilder 3.
>
> They compile and run with no problems from within JBuilder but I can't
> compile them with javac and they won't run using java.exe.
>
> When I try to compile, a typical error message is:
> share.java:11: Class share.Frame1 not found.
> Frame1 frame = new Frame1();
>
> However, Frame1.java is in the same directory as share.java and I haven't
> set classpath.
>
> What am I doing wrong?
>
> If instead, I try to run the class files produced by JBuilder, I get error
> messages similar to:
> Exception in thread "main" java.lang.NoClassDefFoundError: share (wrong
> name: sh
> are/share)
> at java.lang.ClassLoader.defineClass0(Native Method)
> at java.lang.ClassLoader.defineClass(ClassLoader.java:403)
> at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:10
> 1)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
> at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:280)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:237)
>
>
> Can someone help?

About javac:

Because you haven't set the classpath correctly!
classpath is the way to tell javac where to find the resource it needs.

Make sure the files are in correct directory.
Say your share.java contains the "package share;" statement.
Then share.java should be in a subdirectory called "share", and javac should
be called at the parent directory of "share", NOT inside "share".
Also make sure the same for class "Frame1".
Then make sure the classpath contains ".", the current directory.


About JBuilder:

In JBuilder it organizes your files in a certain way, and you have to know
that way to use JBuilder.

First there's project file, .jpr / .jpx. This file stores nothing about your
program; instead it stores information about other program files, so
JBuilder knows where they are, and how to reference them.
This project files will sit in the directory you created it as you "create
new project".

Then you'll need to open a project. Then in menu, choose Project | Project
Properties.
This will display the Project Properties pane, with "Paths" tab selected.

This is where you must study carefully; this tab defines where your files
are, and how JBuilder should make reference to them.

The JDK path is which JDK to use. Locate the parent directory of "bin" of
JDK; by default it is "C:\Jdk1.2.2\".

The Output path is the root directory to place .class files.
e.g. you set this to "C:\Java\". When a class A with no package is compiled,
it will be in "C:\Java\A.class". When a class B is in package Test, it will
be in "C:\Java\Test\B.class".

The Source paths are where the .java files are. You can set as many as
needed. Unlike .class files, .java files can all sit in the same directory,
or each sit in their own direcotries - there's no limit as long as the
Source path is set correctly.
The same goes for Documentation and Required Libraries.

When all these paths are set, you can compile by simply press a button. If
they're not, you'll get the same error you posted.

However, there's something more. If you launch the program from JBuilder's
menu, no problem. Want to launch it from DOS prompt? You gotta be careful.

e.g. The project file is "C:\Java\Project01\p01.jpr".
The main class of the program is "Start.class", which is in package "Main".
The Output path is "\Output".

After compiling in JBuilder, to execute it from DOS prompt, you'll need to
be in directory "C:\Java\Project01\Output", and type "java Main.Start".

If you plan to export the project, you should provide a shortcut for your
users.

-Armstrong.


Will Critchlow

neskaityta,
2000-08-21 03:00:002000-08-21
kam:
Wong Kam Chuen wrote in message <8np6v1$t5...@imsp212.netvigator.com>...

>About javac:
>
>Because you haven't set the classpath correctly!
>classpath is the way to tell javac where to find the resource it needs.
>
>Make sure the files are in correct directory.
>Say your share.java contains the "package share;" statement.
>Then share.java should be in a subdirectory called "share", and javac
should
>be called at the parent directory of "share", NOT inside "share".
>Also make sure the same for class "Frame1".
>Then make sure the classpath contains ".", the current directory.


Thank you for your help. I have done what you suggested and I now get a
slightly different problem (share.java does contain the package share;
statement, and I am now running javac from the parent of the directory
'share' using the commandline 'javac share\share.java'. Is that correct?).
The error message I get now is:

'.\share\Frame1.java:6: Package com.borland.jbcl.layout not found in import.
import com.borland.jbcl.layout.*;'

Where should it be importing this from and how do I tell javac where to find
this?

>
>About JBuilder:
>

<snip details of jbuilder>

>When all these paths are set, you can compile by simply press a button. If
>they're not, you'll get the same error you posted.


I can push that button and compile and all the paths are set correctly.

>
>However, there's something more. If you launch the program from JBuilder's
>menu, no problem. Want to launch it from DOS prompt? You gotta be careful.
>

This is what I'm having trouble with.

>e.g. The project file is "C:\Java\Project01\p01.jpr".
>The main class of the program is "Start.class", which is in package "Main".
>The Output path is "\Output".
>
>After compiling in JBuilder, to execute it from DOS prompt, you'll need to
>be in directory "C:\Java\Project01\Output", and type "java Main.Start".
>

When I try this with the share package described above (where the package is
called share and the main class of the program is share.class compiled using
JBuilder), I get the following message:

'Exception in thread "main" java.lang.NoClassDefFoundError: share/share'

Thank you for your help so far. I wonder if you could give me another push
in the right direction?

Thanks
W

Ashish Shrestha

neskaityta,
2000-08-21 03:00:002000-08-21
kam:
In article <39a0...@news.telinco.net>, "Will Critchlow"

<wan...@currantbun.com> wrote:
> I have written a few little programs in Borland's JBuilder 3.
>
> They compile and run with no problems from within JBuilder but I can't
> compile them with javac and they won't run using java.exe.
>
> When I try to compile, a typical error message is: share.java:11: Class
> share.Frame1 not found.
> Frame1 frame = new Frame1();
>
> However, Frame1.java is in the same directory as share.java and I
> haven't set classpath.
>
> What am I doing wrong?
>
> If instead, I try to run the class files produced by JBuilder, I get
> error messages similar to: Exception in thread "main"

> java.lang.NoClassDefFoundError: share (wrong name: sh are/share)
> at java.lang.ClassLoader.defineClass0(Native Method) at
> java.lang.ClassLoader.defineClass(ClassLoader.java:403) at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:10
> 1)
> at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
> at java.net.URLClassLoader.access$1(URLClassLoader.java:216) at
> java.net.URLClassLoader$1.run(URLClassLoader.java:197) at
> java.security.AccessController.doPrivileged(Native Method) at
> java.net.URLClassLoader.findClass(URLClassLoader.java:191) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:280) at
> sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:275) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:237)
>
>
> Can someone help?
>
> Thanks
>
> W
>
>

You are facing this problem because JBuilder by default puts
all
classes in a package; I believe "share" in your case.

You can easily solve the problem by removing the package
statement from all your *.java files.

Alternatively, a better way, is to go to the parent
directory of
your source files and run java and javac.

Example: ../../parent/share/*.java - your java files

then
cd ../../parent
javac share/share.java

and

java share.share

hope this helps.

ashish

ashish.vcf
0 naujų pranešimų