简体   繁体   English

如何从Linux中的文件夹导入Java文件?

[英]How to import java files from folders in linux?

In my linux, I have my java files that I coped from my windows eclipse project, and now I want to compile it in linux. 在Linux中,我有从Windows eclipse项目中处理过的Java文件,现在我想在Linux中对其进行编译。

The folder structure is 文件夹结构为

PlutoMake.java
java-json.jar
Filter\ColorFilter.java
Filter\Darken.java
Filter\NoFilter.java
Filter\VividLight.java

The PlutoMake file has these imports and some others too like for json PlutoMake文件具有这些导入,其他一些也类似于json

import Filter.ColorFilter;
import Filter.Darken;
import Filter.NoFilter;
import Filter.VividLight;

But when I try to compile plutomake, it says 但是当我尝试编译plutomake时,它说

PlutoMake.java:12: package Filter does not exist
import Filter.ColorFilter;

I already use this to compile it: 我已经使用它来编译它:

javac -cp "java-json.jar" PlutoMake.java

and similarly for other ones too. 其他人也一样。

Does anyone know how to import it? 有人知道如何导入吗?

Thanks 谢谢

You are getting package Filter does not exist error because the Filter.* classes are not present in the class path. 您正在获取package Filter does not exist错误,因为在类路径package Filter does not exist Filter.*类。

First compile the java files in side the folder Filter then compile the PlutoMake.java using javac -cp "java-json.jar;." PlutoMake.java 首先编译java文件中的资料夹Filter然后编译PlutoMake.java使用javac -cp "java-json.jar;." PlutoMake.java javac -cp "java-json.jar;." PlutoMake.java

I'll advice to use some build tool like Maven or Gradle or Ant 我建议使用一些构建工具,例如MavenGradleAnt

If i understand the question correctly. 如果我正确理解了这个问题。 In eclipse just go to fil > Import > Existing Projects into Workspace Select your project and import all your files. 在eclipse中,只需转到fil>导入>现有项目到工作区中,选择您的项目并导入所有文件。 Then hit finish. 然后点击完成。 Are they in the right subdirectories? 它们在正确的子目录中吗?

If you put /usr/share/'classpath', files defined with package Filter should be in /usr/share/Classes/Filter/ try setting java -classpath 如果放置/ usr / share /'classpath',则使用包Filter定义的文件应该位于/ usr / share / Classes / Filter /中,尝试设置java -classpath

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM