Java Package Does Not Exist Error
Are they in the right subdirectories?
If you put /usr/share/stuff
on the class path, files defined with package org.name
should be in /usr/share/stuff/org/name
.
EDIT: If you don't already know this, you should probably read this doc about understanding classpath.
EDIT 2: Sorry, I hadn't realised you were talking of Java source files in /usr/share/stuff
. Not only they need to be in the appropriate sub-directory, but you need to compile them. The .java
files don't need to be on the classpath, but on the source path. (The generated .class
files need to be on the classpath.)
You might get away with compiling them if they're not under the right directory structure, but they should be, or it will generate warnings at least. The generated class files will be in the right subdirectories (wherever you've specified -d
if you have).
You should use something like javac -sourcepath .:/usr/share/stuff test.java
, assuming you've put the .java
files that were under /usr/share/stuff
under /usr/share/stuff/org/name
(or whatever is appropriate according to their package names).
package does not exist error!
This works:
com/example/model/BearExtra.javapackage com.example.model;
public class BearExtra {
public static void go() {
System.out.println("Yay, it works!");
}
}
com/example/web/Bear.javapackage com.example.web;
import com.example.model.*;
public class Bear {
public static void main(String[] args) {
BearExtra.go();
}
}
Now, to compile and run these classes, go to the directory where you can "see" the com
folder and do:
javac -cp . com/example/model/*.java com/example/web/*.java
java -cp . com.example.web.Bear
Windowsjavac -cp . com\example\model\*.java com\example\web\*.java
java -cp . com.example.web.Bear
and the following is being printed to the console:
Yay, it works!
java package <package> does not exist -> Java Error
If you have a directory structure like this:
mySrc
controle
modelo
visao
You need to compile from the "top" of the directory structure, and you need to specify a full path to the file. You also need the files in modelo
and visao
compiled so the .class files are available.
myScr> javac controle\BibliotecaMusicalControle.java
\
is a file separator on Windows. On Mac and Unix it's /
.
Java "package does not exist" error in UNIX
Thank you guys! I just found out running "ant -buildfile build.xml" and then "ant run -buildfile build.xml" does the magic for you!
Java: package does not exist
From your error it looks like your "other program" B.java
is not in the same directory (E:\stuff\Java) of 'A.java'. This means that when you try to compile B.java
the compiler does not know where to find class pack.A
. To "make A visible" you must add pack.A
to your classpath, which means compiling with:
javac -cp ".;<path_to_add>" B.java
In your case <path_to_add>
should be E:\stuff\Java
. This sets your classpath to not only the current directory (.
) but also the directory where your pack
package is.
To run your program you again have to add pack.A
to you class path:
java -cp ".;<path_to_add>" B
Where again <path_to_add>
should be E:\stuff\Java
.
Here I am assuming you are using windows. On Unix the -cp
option as a slightly different syntax: -cp ".:<path_to_add>"
where the ;
has been replaced by :
.
package does not exist when running the application
I'm afraid it may be a problem with your IDE.
Check if you have the last version and try to run also with other (Eclipse,STS,...).
I hope this help you.
Related Topics
How to Send Date in Rest API in Post Method
Enter Array Without Knowing Its Size
Java: How to Check If Object Is Null
403 Forbidden When I Try to Post to My Spring API
How to Update Each Element in a List in Java 8 Using Stream API
How to Know If All the Variables in a Class Are Null
How to Set a Timeout on a Spring Boot Rest API
How to Use Variables in One Method into Another Method
How to Bypass Google Recaptcha for Testing Using Selenium
How to Upload a File and Json Data in Postman
How to Determine If a List of String Contains Null or Empty Elements
How to Pass JavaScript Values to Scriptlet in Jsp
How to Print Out All the Elements of a List in Java
Regular Expression to Remove Everything But Characters and Numbers
How to Sort Integer Digits in Ascending Order Without Strings or Arrays
Java - Replace New Line Character by \N
Java Stream:Create New List from 2 Lists Keeping Only Matching Values