Results 1 to 8 of 8
Thread: learning packages
- 03-25-2010, 01:31 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
learning packages
hello I am not able to compile this package structure pleas help.
Dir structure
c:\jpro\p\testclass1.java
c:\jpro\p\testclass2.java
both the class are created in plackage p in directory c:\jpro
testclass1
<code>
package p;
class testclass1
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
</code>
testclass2
<code>
package p;
class testclass2
{
public static void main(String[] args)
{
System.out.println("testclass2!");
}
}
</code>
I am compiling
C:\jpro>javac p.testclass2.java
javac: file not found: p.testclass2.java
Usage: javac <options> <source files>
use -help for a list of possible options
but if i compile from inside the package it compiles fine but do not run.I dont know missing some thing really silly in here please help
C:\jpro\p>java testclass1
Exception in thread "main" java.lang.NoClassDefFoundError: testclass1 (wrong name: p/testclass1)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknow n Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)Last edited by shashanksworld; 03-25-2010 at 01:33 PM.
- 03-25-2010, 01:46 PM #2
Member
- Join Date
- Mar 2010
- Posts
- 20
- Rep Power
- 0
go to the directory where the testClass1 and 2 files are and type:
javac testClass1.java
javac testClass2.java
Theres no such thing as "compiling a package"
- 03-25-2010, 02:34 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
javac p/testclass2.java
- 03-25-2010, 05:26 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you compile testclass1 class? Seems you've compile a one class and run the other.
- 03-25-2010, 05:35 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
As i pointed out, they're not using javac correctly.
"p.testclass2.java" is not the correct filename, which is why it's complaining.
It's a path, not a package...so "p\testclass2.java".
But, as you say, they don't appear to be runnin gthe same file that they're compiling.
- 03-26-2010, 02:48 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Simply he compiles a one and try to run another in a different folder path, in wrong way. Don't know that OP got it clearly and tried it out.
- 03-26-2010, 09:33 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,471
- Rep Power
- 16
Hard to tell since they haven't come back...and it's just us two chattering away.
:)
- 03-26-2010, 12:03 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Pre-requisites for learning JSP
By xtiano77 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-23-2010, 06:03 PM -
e-learning
By Vipan Konnect in forum Advanced JavaReplies: 3Last Post: 11-21-2009, 04:29 PM -
Self-directed learning
By Mr.Beans in forum Forum LobbyReplies: 3Last Post: 05-05-2009, 10:40 PM -
Learning Java
By jjoshua2 in forum New To JavaReplies: 2Last Post: 12-20-2008, 02:46 AM -
Importing packages from the packages within same application.
By sta2003 in forum New To JavaReplies: 3Last Post: 02-12-2008, 11:03 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks