473,385 Members | 1,780 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,385 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 2536
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.