Java Packaging woes
문제
ok 그래서 Java의 테스트 파일에서 Somemore를 사용하기로 결정했습니다. 나는 홈 PC에서 폴더를 만들고 내 작업 PC에 가져 오기로 결정했습니다.문제가 있니?내가 컴파일 할 때 - 나는 얻는다 :
C:\Documents and Settings\djasnowski\Desktop\gJson\readGoogle.java:1: package com.google.gson does not exist
import com.google.gson.*;
^
C:\Documents and Settings\djasnowski\Desktop\gJson\readGoogle.java:37: cannot find symbol
symbol : class Gson
location: class readGoogle
data = new Gson().fromJson(fileString, Data.class);
^
2 errors
.
재미 있습니다.나는 내 파일을 눌러 내지 않았으며 우리 홈 PC에서 잘 작동했고 이제는 이것을 얻습니다.파일은 멋지게 설정됩니다.Google JSON Java 파일이 들어있는 폴더에 COM.Google.gson이 있고 올바른 디렉토리에 내 Googleread.java 파일이 있습니다. 그리고 My Map1.txt도 있습니다.나는 그렇게 생각한다.
여기 내 파일이 있습니다 :
import com.google.*;
import java.util.*;
import java.io.*;
public class readGoogle {
public static String MapTitle;
public static Data data;
public static Item item;
public static String dan;
public static FileReader fr;
public static void main(String[] args) {
try {
fr = new FileReader("map1.txt");
}catch(FileNotFoundException fne) {
fne.printStackTrace();
}
StringBuffer sb = new StringBuffer();
char[] b = new char[1000];
int n = 0;
try {
while ((n = fr.read(b)) > 0) {
sb.append(b, 0, n);
}
}catch(IOException rex) {
rex.printStackTrace();
}
String fileString = sb.toString();
try {
data = new Gson().fromJson(fileString, Data.class);
}catch (Exception er) {
er.printStackTrace();
}
System.out.println("Name of map: " + data.getTitle());
System.out.println("File of map: " + data.getName());
System.out.println("Current Map: " + data.getCurrentMap());
System.out.println("Right Map: " + data.getRightMap());
}
public static class Item {
public static String name;
public static int x;
public int y;
public static String getName() { return name; }
public static int getX() { return x; }
public int getY() { return y; }
public void setName(String name) { this.name = name; }
public void setX(int x) { this.x = x; }
public void setY(int y) { this.y = y; }
}
public static class Data {
private String name;
private String title;
private int currentMap;
private int leftMap;
private int rightMap;
private int upMap;
private int downMap;
private List<Item> items;
private int[][] map;
public String getName() { return name; }
public String getTitle() { return title; }
public int getCurrentMap() { return currentMap; }
public int getUpMap() { return upMap; }
public int getDownMap() { return downMap; }
public int getLeftMap() { return leftMap; }
public int getRightMap() { return rightMap; }
public List<Item> getItems() { return items; }
public int[][] getMap() { return map; }
public void setName(String name) { this.name = name; }
public void setTitle(String title) { this.title = title; }
public void setCurrentMap(int currentMap) { this.currentMap = currentMap; }
public void setItems(List<Item> items) { this.items = items; }
public void setMap(int[][] map) { this.map = map; }
}
}
. 해결책
첫 번째 오류는 다음과 같습니다 :
package com.google.gson does not exist
.
그런 다음 GSON jar를 CLASSPATH에 추가하고 컴파일을 다시 시도하십시오. 클래스 경로를 변경하는 세부 사항은 툴 세트에 종속됩니다.이 단계는 명령 줄에서 javac
의 핸드 호출에 비해 IDE에 비해 IDE가 표면적으로 다릅니다. 클래스 경로를 조작하는 방법을 모르고 명령 줄을 사용하는 방법을 모르면 manual 또는 Google It . 질문에서 파일 레이아웃을 이해할 수 없으므로 더 많은 정보없이 더 이상 구체적 일 수 없습니다.
이 문제를 해결하면 Apache Maven 와 같은 도구를 사용하여 종속성 관리를 자동화하기 위해 다음을 고려할 수 있습니다. 편집 및 포장.
제휴하지 않습니다 StackOverflow