简体   繁体   中英

How to specify a relative file path in a standard Maven project

My Maven project needs to load data to database, and the import.sql contains the following:

LOAD DATA LOCAL INFILE 
`'/home/jack/ubuntu/bword/src/main/resources/Term.txt' INTO TABLE Term FIELDS TERMINATED BY '\t'  LINES TERMINATED BY '\n' (id,name);`

The path used here is the absolute path on my machine. How can I specify a relative path to make it work? I tried these:

/bword/src/main/resources/Term.txt
../bword/src/main/resources/Term.txt
../bword/src/main/resources/Term.txt
../src/main/resources/Term.txt

None of these work. The file is located at src/main/resources , a default directory in a Maven directory.

I am using JBoss and hibernate, JPA.

IMHO you can't do it.

Your application is web application ( I take a look on chat ). Maven can package import.sql and Term.txt into the application. Both files are visible on classpath. Hibernate scans classpath, finds import.sql and execute it.

But when import.sql is proceed, the command

LOAD DATA LOCAL INFILE 'file_name' ...

is executed. 'file_name' is resolved against current working dir.

  1. Is Term.txt visible in filesystem? I don't think so.
  2. Does you application control current directory of JBoss process? No

Summary:

  1. Term.txt is not visible as file on JBoss filesystem
  2. LOAD DATA LOCAL INFILE needs file on JBoss filesystem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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