【发布时间】:2016-07-25 12:50:31
【问题描述】:
所以,我的包结构是我有一个 src 文件夹,里面有我的代码,里面有一个 exec 文件夹,里面有一个类和三个方法,我的主类和两个 jar。
我的 exec 类如下所示:
package com.xxx.exec;
import au.com.bytecode.opencsv.CSVReader;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
* Created by xxx on 24/07/16.
*/
public class ApiAccess {
public void getConsoleInput() throws Exception {
Console console = System.console();
if (console == null) {
throw new Exception("Unable to fetch console");
}
System.out.println("Please enter the location:");
getAPIData(console.readLine());
}
private void writeCsv(InputStream input) {
try {
CSVReader locationData = new CSVReader(new InputStreamReader(input));
locationData.close();
System.out.println(input);
}
catch (Exception e) {
System.out.println("Something went wrong while creating the csv:" + e);
}
}
private void getAPIData(String location) throws IOException {
String url = "http://exec.goeuro.com/exec/v2/position/suggest/en/";
String charset = StandardCharsets.UTF_8.name();
String query = String.format(url + "%s", URLEncoder.encode(location, charset));
URLConnection connection = new URL(query).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
// String line;
// StringBuilder text = new StringBuilder();
// BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
// while((line = reader.readLine()) != null) {
// text.append(line).append(" ");
// }
//
// writeCsv(text.toString());
writeCsv(connection.getInputStream());
}
}
我的终端命令如下所示:
javac -cp ".:lib/*:opencsv-2.41.jar" -d src $(find ./src/* | grep .java)
我得到这个错误:
./src/com/goeuro/exec/ApiAccess.java:3: error: package au.com.bytecode.opencsv does not exist
import au.com.bytecode.opencsv.CSVReader;
^
./src/com/goeuro/exec/ApiAccess.java:29: error: cannot find symbol
CSVReader locationData = new CSVReader(new InputStreamReader(input));
^
symbol: class CSVReader
location: class ApiAccess
./src/com/goeuro/exec/ApiAccess.java:29: error: cannot find symbol
CSVReader locationData = new CSVReader(new InputStreamReader(input));
^
symbol: class CSVReader
location: class ApiAccess
3 errors
提前感谢您的任何回答!
当前目录结构(我在目录前面加了一个反斜杠):
/src >
-/com.xxx >
-Main.java,
-/exec >
-ApiAccess,
-opencsv-2.41.jar >
-/au.com.bytecode.opencsv,
-commons-lang3-3.0.1.jar
【问题讨论】:
-
请告诉我们JAR文件相对于当前目录的位置。
-
@StephenC 嘿,我添加了结构 :)
-
我在等你修复它,以便它 1) 可读和 2) 准确
-
@StephenC 我修复了可读性。对于那个很抱歉。否则是准确的。在使用 maven 安装之前,我在外部 lib 文件夹中有依赖项,但将它们解压缩并将它们放在 exec 文件夹中,以尝试如果我只是将文件放在同一位置,是否会让我的生活更轻松,但我也更改了路径之后我的 intellij 项目结构。
-
@StephenC 我添加了一个屏幕截图,不知道我被允许这样做:) CSVMaker 文件是空的且不重要,它是我之前尝试过的东西的剩余部分。