[英]Java code worked in Windows but not in Linux (Fedora or Ubuntu)
So I have this small Java project for study purposes where I am learning how to call functions from other java files and reference them with import.所以我有这个小的 Java 项目用于学习目的,我正在学习如何从其他 java 文件中调用函数并通过导入引用它们。 Everything works as inteded in Windows and I'm happy with it, but I just tried to work in the same project using Fedora and Ubuntu, and seems like the imports and package references just don't work.
一切都在 Windows 中正常工作,我对此很满意,但我只是尝试使用 Fedora 和 Ubuntu 在同一个项目中工作,并且似乎导入和 ZEFE90A8E604A7C840E88D03AD67FZ6 引用只是不工作。
I get this trying to compile main java file:我得到这个试图编译主 java 文件:
$ javac Ejercicio01.java
Ejercicio01.java:3: error: package actividad05.introduceDatos does not exist
import static actividad05.introduceDatos.Pregunta.*;
^
Ejercicio01.java:4: error: package actividad05.operaciones does not exist
import static actividad05.operaciones.Valores.*;
^
Ejercicio01.java:5: error: package actividad05.operaciones.algebraicas does not exist
import static actividad05.operaciones.algebraicas.Operaciones.*;
^
Ejercicio01.java:6: error: package actividad05.operaciones.geometricas does not exist
import static actividad05.operaciones.geometricas.Operaciones.*;
^
Ejercicio01.java:13: error: cannot find symbol
opcion = pideEntero("\nElija una opcion:"
^
symbol: method pideEntero(String)
location: class Ejercicio01
Ejercicio01.java:25: error: cannot find symbol
muestraPi();
^
symbol: method muestraPi()
location: class Ejercicio01
Ejercicio01.java:28: error: cannot find symbol
muestraValorAleatorio();
^
symbol: method muestraValorAleatorio()
location: class Ejercicio01
Ejercicio01.java:31: error: cannot find symbol
double num = pideDouble("Introduzca un valor: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:32: error: cannot find symbol
muestraSeno(num);
^
symbol: method muestraSeno(double)
location: class Ejercicio01
Ejercicio01.java:35: error: cannot find symbol
num = pideDouble("Introduzca un valor: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:36: error: cannot find symbol
muestraCoseno(num);
^
symbol: method muestraCoseno(double)
location: class Ejercicio01
Ejercicio01.java:39: error: cannot find symbol
muestraRaizCuadrada();
^
symbol: method muestraRaizCuadrada()
location: class Ejercicio01
Ejercicio01.java:42: error: cannot find symbol
double base = pideDouble("Introduzca base: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:43: error: cannot find symbol
double exp = pideDouble("Introduzca exponente: ");
^
symbol: method pideDouble(String)
location: class Ejercicio01
Ejercicio01.java:44: error: cannot find symbol
calculaPotencia(base, exp);
^
symbol: method calculaPotencia(double,double)
location: class Ejercicio01
15 errors
My main Java file references the other functions like this:我的主要 Java 文件引用了其他函数,如下所示:
package actividad05.main;
import static actividad05.introduceDatos.Pregunta.*;
import static actividad05.operaciones.Valores.*;
import static actividad05.operaciones.algebraicas.Operaciones.*;
import static actividad05.operaciones.geometricas.Operaciones.*;
public class Ejercicio01 {
Meaning that Ejercicio01.java is in the folder src/actividad05/main, and the functions imported are in src/actividad05/introduceDatos/Pregunta.java etc, etc.意思是Ejercicio01.java在文件夹src/actividad05/main,导入的函数在src/actividad05/introduceDatos/Pregunta.java等。
My first thought is that this is probably a classpath problem.我的第一个想法是,这可能是一个类路径问题。 Check where your source code is (.java files) and where you compile them to (.class files).
检查源代码的位置(.java 文件)以及将它们编译到的位置(.class 文件)。 Then check how you are trying to run the application, is the location of all the.class files on the classpath?
然后检查您是如何尝试运行应用程序的,是类路径上所有 .class 文件的位置吗? In this case it has little to do with the OS difference, but with compilation and execution commands and file locations.
在这种情况下,它与操作系统差异无关,而是与编译和执行命令以及文件位置有关。
A problem which sometimes occurs when running compiled code on another OS is that the JDK or JRE has a different vendor or version.在另一个操作系统上运行编译代码时有时会出现的问题是 JDK 或 JRE 具有不同的供应商或版本。 Are you using the Oracle or OpenJDK?
您使用的是 Oracle 还是 OpenJDK? Which version?
哪个版本? If the version is different, even compilation might run into trouble because some Java features are different.
如果版本不同,甚至编译也可能会遇到麻烦,因为 Java 的一些特性不同。
But the above output points in the direction of the first issue.但是上面的output指向了第一个问题的方向。
EDIT: the problem that the package is not found could mean that you don't have the.java file under the directories matching the package names, or that you are not calling the compiler on the root package (the source directory). EDIT: the problem that the package is not found could mean that you don't have the.java file under the directories matching the package names, or that you are not calling the compiler on the root package (the source directory).
Check out: https://www.webucator.com/how-to/how-compile-packages-java.cfm查看: https://www.webucator.com/how-to/how-compile-packages-java.cfm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.