Results 1 to 20 of 23
- 02-08-2012, 08:04 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
javac cannot compile my source which uses a package
Hi,
I'm learning java and cannot step over this problem:
I have created a new directory to store my packages. This is in my home directory: <myhome>/prog/j/packages and there is a java source file: <myhome>/prog/j/packages/SamplePackedClass.java. This file contains only this:
There is another java source file in <myhome>/prog/j/UsePredefinedPackage.java:Java Code:package samplepackage; public class SamplePackedClass { }
Tutorials and online helps write about compiling that, I have to create a new environment option to compile it correctly:Java Code:import samplepackage.*; public class UsePredefinedPackage { }
Yeye, but doesn't work:Bash Code:export CLASSPATH=[I]<myhome>/prog/j/packages[/I]
I tried to use -cp flag also, as can be read in javac manual. Same result.Bash Code:javac UsePredefinedPackage.java UsePredefinedPackage.java:1: error: package samplepackage does not exist import samplepackage.*; ^ 1 error
I mess somethig, but really do not know what. Can somebody help?
Another question: if CLASSPATH way is right, how can I give more, than one? Some env option uses ":" to separate, but I don't know about this any more.
- 02-08-2012, 09:05 PM #2
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
Re: javac cannot compile my source which uses a package
if u wanted to use more than one environment variable while compiling the code. USE the command set path="ur environment path " and then start executing
all the files in that location will be available from then. and make sure u use this command when ever u compile ur code
- 02-08-2012, 09:06 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 60
- Rep Power
- 0
Re: javac cannot compile my source which uses a package
if u wanted to use more than one environment variable while compiling the code. USE the command set path="ur environment path " and then start executing
all the files in that location will be available from then. and make sure u use this command when ever u compile ur code
- 02-08-2012, 09:29 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-08-2012, 09:30 PM #5
Re: javac cannot compile my source which uses a package
Your package name must be the same as the name of the folder containing it.
Your .java files are not in the correctly named folders or the package statement is wrong. They must match.
- 02-08-2012, 10:21 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-08-2012, 10:22 PM #7
Re: javac cannot compile my source which uses a package
If you want help you will have to say more than "it didn't work".
What you have posted so far will not work. You need to change it. What have you changed it to?
What errors are you getting?
- 02-08-2012, 10:29 PM #8
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-08-2012, 10:45 PM #9
Re: javac cannot compile my source which uses a package
I have no idea of what you are currently working with. There are folders, source files, classpath settings, the current folder when you execute the javac command, the commandline, etc
Somewhere in all those different files, settings etc things are not right. Unless you completely describe it all, there is no way to guess the dozens of different ways it could be wrong.
- 02-08-2012, 11:03 PM #10
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-08-2012, 11:08 PM #11
Re: javac cannot compile my source which uses a package
Post the console contents from when you compile. The folder name, the contents of the folder (use dir command) and the commandline
- 02-09-2012, 09:21 AM #12
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
Re: javac cannot compile my source which uses a package
OK. I do not understand, because... it works. I've restarted system and it is working now. javac compiled my new class... Very strange. I have to know the reason of this effect to keep clear of this mistake. It is my mistake, but still I do not know where. Can you explain to me?
It is just for mystify me:
(Notice please, I didn't use -cp path option.)Bash Code:javac UsePredefinedPackage.java
This file is in my <myhome>/prog/j folder and compiled.
The package is <myhome>/prog/j/samplepackage/SamplePackedClass.java (I have precompiled it previously and <myhome>/prog/j/samplepackage/SamplePackedClass.class file exists of course.)
And now I want to see my CLASSPATH env option:
Regenerating CLASSPATH results compiler error again:Bash Code:echo $CLASSPATH (nothing)
I mess something, sure. Need still help. :(Bash Code:javac UsePredefinedPackage.java UsePredefinedPackage.java:1: error: package samplepackage does not exist import samplepackage.*; ^ 1 error
Last edited by jpocok; 02-09-2012 at 09:24 AM.
- 02-09-2012, 12:31 PM #13
Re: javac cannot compile my source which uses a package
Post the console contents from when you compile. The folder name, the contents of the folder (use dir command) and the commandline.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
- 02-09-2012, 12:46 PM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
- 02-09-2012, 09:32 PM #15
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-09-2012, 09:36 PM #16
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-09-2012, 09:42 PM #17
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Re: javac cannot compile my source which uses a package
As a rule of thumb: javac compiles files while java runs classes (optionally in a .jar file). If you want to compile a file named UsePredefinedPackage.jave you'd better make sure that file is in your current working directory; otherwise you have to supply the path to that file.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-09-2012, 09:55 PM #18
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
- 02-09-2012, 09:56 PM #19
Re: javac cannot compile my source which uses a package
I didn't see the console contents that shows:I've already pasted everything several times.
1) the current directory that the command was issued in
2) the contents of the current directory
On windows this is what is shown:
The Orange is the current directory path. Below is the contents of that directory.
Microsoft Windows XP [Version 5.1.2600]
D:\JavaDevelopment\Testing\ForumQuestions\rwm3>dir
Volume in drive D is Work
Volume Serial Number is 0C24-B38C
Directory of D:\JavaDevelopment\Testing\ForumQuestions\rwm3
09/11/2009 01:35 AM <DIR> .
09/11/2009 01:35 AM <DIR> ..
07/04/2001 05:21 PM 20,768 BB.gif
06/09/2001 01:17 AM 695 Comp.java
06/30/2001 12:40 AM 885 Dot.gif
05/15/2001 01:46 AM 2,419 R1.gif
07/20/2001 10:30 PM 1,027 rwm3.html
07/21/2001 10:07 AM 7,784 rwm3.java
6 File(s) 33,578 bytes
2 Dir(s) 7,023,009,792 bytes free
D:\JavaDevelopment\Testing\ForumQuestions\rwm3>
- 02-09-2012, 10:03 PM #20
Member
- Join Date
- Feb 2012
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Can't compile if using anything from java.nio package
By Phynx in forum New To JavaReplies: 11Last Post: 01-04-2012, 08:00 PM -
I try to compile my source code, However it says javac: file not found: Hello.java
By waao in forum New To JavaReplies: 7Last Post: 08-29-2011, 06:35 PM -
javac does not import package from jar in 1.6
By tonydr in forum Advanced JavaReplies: 0Last Post: 05-26-2010, 10:34 PM -
error while compile code using javac
By suri in forum New To JavaReplies: 3Last Post: 01-20-2010, 09:10 AM -
Compile and Run a Java package
By hussain in forum New To JavaReplies: 1Last Post: 09-10-2009, 09:15 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks