473,287 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

compiling java programs in Unix

I'm having trouble compiling my program in Unix. I initially developed it on Windows in Eclipse. I have two files: Tokenizer.java and TokenizerMain.java. They are both in a directory called "tokenizer" I'm compiling from my home directory:

% javac tokenizer/TokenizerMain.java
./tokenizer/Tokenizer.java:5: 'class' or 'interface' expected
package tokenizer;
^
tokenizer/TokenizerMain.java:2: cannot access tokenizer.Tokenizer
bad class file: ./tokenizer/Tokenizer.java
file does not contain class tokenizer.Tokenizer
Please remove or make sure it appears in the correct subdirectory of the classpath.
import tokenizer.Tokenizer;
^
2 errors

And those are the errors I receive. It works fine when I compile it via Eclispe.
Under my TokenizerMain class I typed:
package tokenizer;
import tokenizer.Tokenizer;
Under my Tokenizer class I typed:
package tokenizer;

Any help would be appreciated.
Nov 14 '08 #1
4 2533
Ganon11
3,652 Expert 2GB
First, when using javac to compile your .java files in packages, you use a period (.) instead of the forward slash (/) to separate the package name from the file name:

Expand|Select|Wrap|Line Numbers
  1. javac tokenizer.TokenizerMain.java
(That is, I think so. I've had to actually go into the folder containing the .java files and compile them using javac *.java)

Second, if two classes are in the same package, they don't need to be imported to each other - they automatically have access to each other.
Nov 14 '08 #2
JosAH
11,448 Expert 8TB
First, when using javac to compile your .java files in packages, you use a period (.) instead of the forward slash (/) to separate the package name from the file name:

Expand|Select|Wrap|Line Numbers
  1. javac tokenizer.TokenizerMain.java
(That is, I think so. I've had to actually go into the folder containing the .java files and compile them using javac *.java)
No, javac compiles files so it uses those slashes; java runs classes so it uses
those dots. Compiling them all together is the way to go. Also type in 'javac' and
see what flags to use to point the compiler where the .class files can be found
and the .java source files can be found.

kind regards,

Jos
Nov 14 '08 #3
Ganon11
3,652 Expert 2GB
...right. This is why I should try this before I speak.
Nov 14 '08 #4
Turns out I didn't even need the package stuff. I just ran javac <all my files> and it worked. Thanks for helping out you two.
Nov 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
5
by: Jo Vermeulen | last post by:
Hello, I was wondering if Java supports a feature of C# (or .NET in general), namely compiling code at runtime. This is nice for scripting purposes. Users can script the application in real...
40
by: Eitan | last post by:
Hello, I know Java-Applet (written for JBuilder). I would like to know about dotnet technology, pros and cons in comparation to Java-Applet technololgy. Can I write a program in dotnet, like...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
10
by: Tomás Ó hÉilidhe | last post by:
I'd post this on a gcc newsgroup but I'd be more productive talking to the wall. Anyway, let's say someone throws some source code at you for a particular program and says, "Just compile it, it...
29
by: s0suk3 | last post by:
Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to...
60
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
On May 3, 8:09 am, apati...@gmail.com wrote: A programmer that uses Vista? :O Vista is a hog of an operating system. Downgrade to Windows XP or get yourself a Linux distro.
8
by: marknvicf | last post by:
I have read a bit about the endian differences, got a couple of jar/libs to help (Android and com.mindprod), but still am not sure how to fix this program that I have (written in JDK 1.4 by someone...
4
by: anon538 | last post by:
I have been interested in switching from Java to C# for a long time now. I typically write small, stand alone programs for contests. Each program is completely self contained. I am used to, in...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.