이 자바 코드를 Eclipse에서 실행할 때 다음 오류가 발생합니다. 여기 리소스 지정이 허용되지 않음 오류
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Resource specification not allowed here for source level below 1.7 The type Transaction is not visible tx cannot be resolved
at neo4jTesting.EmbeddedNeo4j.createDb(EmbeddedNeo4j.java:52) at neo4jTesting.EmbeddedNeo4j.main(EmbeddedNeo4j.java:38)
는
import java.io.File; import java.io.IOException; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.kernel.impl.util.FileUtils;
public class EmbeddedNeo4j {
private static final String DB_PATH = "target/neo4j-hello-db";
public String greeting;
// START SNIPPET: vars
GraphDatabaseService graphDb;
Node firstNode;
Node secondNode;
Relationship relationship;
// END SNIPPET: vars
// START SNIPPET: createReltype
private static enum RelTypes implements RelationshipType
{
KNOWS
}
// END SNIPPET: createReltype
public static void main(final String[] args)
{
EmbeddedNeo4j hello = new EmbeddedNeo4j();
hello.createDb();
hello.removeData();
hello.shutDown();
}
void createDb()
{
clearDb();
// START SNIPPET: startDb
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
registerShutdownHook(graphDb);
// END SNIPPET: startDb
// START SNIPPET: transaction
try (Transaction tx = graphDb.beginTx())
{
// Database operations go here
// END SNIPPET: transaction
// START SNIPPET: addData
firstNode = graphDb.createNode();
firstNode.setProperty("message", "Hello, ");
secondNode = graphDb.createNode();
secondNode.setProperty("message", "World!");
relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
relationship.setProperty("message", "brave Neo4j ");
// END SNIPPET: addData
// START SNIPPET: readData
System.out.print(firstNode.getProperty("message"));
System.out.print(relationship.getProperty("message"));
System.out.print(secondNode.getProperty("message"));
// END SNIPPET: readData
greeting = ((String) firstNode.getProperty("message"))
+ ((String) relationship.getProperty("message"))
+ ((String) secondNode.getProperty("message"));
// START SNIPPET: transaction
tx.success();
} finally {
tx.finish();
}
// END SNIPPET: transaction
}
private void clearDb()
{
try
{
FileUtils.deleteRecursively(new File(DB_PATH));
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
void removeData()
{
try (Transaction tx = graphDb.beginTx())
{
// START SNIPPET: removingData
// let's remove the data
firstNode.getSingleRelationship(RelTypes.KNOWS, Direction.OUTGOING).delete();
firstNode.delete();
secondNode.delete();
// END SNIPPET: removingData
tx.success();
} finally {
tx.finish();
}
}
void shutDown()
{
System.out.println();
System.out.println("Shutting down database ...");
// START SNIPPET: shutdownServer
graphDb.shutdown();
// END SNIPPET: shutdownServer
}
// START SNIPPET: shutdownHook
private static void registerShutdownHook(final GraphDatabaseService graphDb)
{
// Registers a shutdown hook for the Neo4j instance so that it
// shuts down nicely when the VM exits (even if you "Ctrl-C" the
// running application).
Runtime.getRuntime().addShutdownHook(new Thread()
{
@Override
public void run()
{
graphDb.shutdown();
}
});
}
// END SNIPPET: shutdownHook }
내 사과에서 인 코드,하지만 난 방법을 간단한과 문제를 설명하기 위해 아무 생각이 없다 해결책.
모든 조언을 주시면 감사하겠습니다.
편집 한
덕분에, 나는 1.7에 자바를 업데이트 한 새로운 오류가 인사를하고있다. 이것은 Eclipse가 아닌 컴파일러에서 가져온 것입니다.
자원 유형의 거래는 다시 한번
java.lang.AutoCloseable를 구현하지 않는, 어떤 도움에 감사드립니다.
Eclipse는 자체 파서 및 컴파일러를 구현하므로 "마커"창의 오류와 컴파일러 오류 사이에는 많은 차이가 없습니다. – chrylis
'try'-with-resources 블록에서 사용 된 자원은'AutoCloseable'을 구현해야합니다; 그것이 블록이 작동하는 방식입니다. Neo4J의'Transaction' 인터페이스는 그것을 확장하지 않습니다. 아마도 새로운 2.0 시리즈는 그것을 개장하지 않습니다. Neo4J에 대한 버그를 제기하는 것이 좋습니다. 그 동안은 수동으로해야합니다. – chrylis