0

This must be a super overasked question. Although here goes:

I have a java file for testing around (hworld.java) and am trying to import conio.jar, a JAR which is a wrapper of Conio. The JAR contains only one class file (conio.class) and META-INF. Trying to do import conio.* or import conio.conio shows me this:

C:\Documents and Settings\Nick\Desktop>javac -cp *.jar; hworld.java
hworld.java:3: error: package conio does not exist
import conio.*;
^
1 error

And compiling it like javac -cp conio.jar hworld.java still errors out while compiling. I even extracted the jar and had conio.class in the same directory as hworld.java but to no avail. The JAR is in the same directory as hworld.java, as well.

Anyone have any idea on how to fix this?

Name McChange
  • 2,750
  • 5
  • 27
  • 46
  • If the Conio class really isn't in a package, just try import Conio; – rooftop May 01 '12 at 21:15
  • @rooftop hworld.java:3: error: '.' expected import conio; – Name McChange May 01 '12 at 21:16
  • @SuperDisk if it is no package (AKA default package) then you don't need to import it at all... Remove the import line altogether. – yair May 01 '12 at 21:19
  • @yair That doesn't make any sense, how do I tell the compiler to use conio.jar without importing it? – Name McChange May 01 '12 at 21:24
  • @SuperDisk I refer the `import` line in `hworld.java`. The jar, however, should be in the classpath. You do that through the `-cp` option of the `javac` command. – yair May 01 '12 at 21:29

3 Answers3

0

It's actually not possible. You need to put the other class in a package if you want to import it.

What's the syntax to import a class in a default package in Java?

Community
  • 1
  • 1
rooftop
  • 3,031
  • 1
  • 22
  • 33
0

You don't mention whether conio.class is defined in package conio. If it is not, then simply use the class without importing it. Remove the import.

Lyn Headley
  • 11,368
  • 3
  • 33
  • 35
  • ..This seems like a very dumb thing for java to have! But it does work. Although, to a new coder looking at an existing codebase, they'd never know where all the functions are defined unless he/she looked at the makefile or something. How silly. – Name McChange May 01 '12 at 21:52
0

Find out what package Conio is in - an easy way to do this is to open the jar as a zip file, the package will correspond with the folder structure of the archive. For example if Conio is in x/y/z then import x.y.z.Conio and compile/run with conio.jar on the classmate.

user793370
  • 31
  • 3