Running java jar outside eclipse requiring files in bin dir -
i'm developing using eclipse , i'm using api requires files in /bin directory (which path mean in java don't know). exported app jar , put required files in same directory jar file, when run app using terminal, app not able locate files. i'm unable understand paths issue.
i'm running app command:
java -jar app.jar
i changed terminal directory directory contains jar file , tried with:
java -cp . -jar app.jar
that didn't work.
edit: error application not able locate required files. in eclipse had put files in /bin dir in order api locate them.
here's full exception:
exception in thread "main" java.io.ioexception: failed find resource /cmu/arktweetnlp/50mpaths2 @ cmu.arktweetnlp.util.basicfileio.getresourcereader(basicfileio.java:233) @ cmu.arktweetnlp.impl.features.wordclusterpaths.<init>(wordclusterpaths.java:29) @ cmu.arktweetnlp.impl.features.featureextractor.initializefeatureextractors(featureextractor.java:146) @ cmu.arktweetnlp.impl.features.featureextractor.<init>(featureextractor.java:30) @ cmu.arktweetnlp.tagger.loadmodel(tagger.java:39) @ com.postest.main(postest.java:22)
terminal content:
macbook-pro:arabictwittereye ma$ ls csvarabictwittereye.jar log resources cmu profiles tweets.csv macbook-pro:arabictwittereye ma$
here's simple java code:
public static void main(string[] args) { tagger tagger = new tagger(); string modelfilename = "model.20120919"; system.out.println( "loading model ..." ); try { tagger.loadmodel(modelfilename); } catch (ioexception e) { e.printstacktrace(); } system.out.println( "done loading model." ); }
here's source code api:
public class wordclusterpaths implements featureextractorinterface { /** todo should moved config somehow **/ public static string clusterresourcename = "/cmu/arktweetnlp/50mpaths2"; public static hashmap<string,string> wordtopath; public wordclusterpaths() throws ioexception { // log.info("loading clusters"); //read in paths file bufferedreader breader = basicfileio.getresourcereader(clusterresourcename); string[] splitline = new string[3]; string line=basicfileio.getline(breader); wordtopath = new hashmap<string,string>(); while(line != null){ splitline = line.split("\\t"); wordtopath.put(splitline[1], splitline[0]); line = basicfileio.getline(breader); } // log.info("finished loading clusters"); }
also check this:
public static bufferedreader getresourcereader(string resourcename) throws ioexception { assert resourcename.startswith("/") : "absolute path needed resource"; inputstream stream = basicfileio.class.getresourceasstream(resourcename); if (stream == null) throw new ioexception("failed find resource " + resourcename); //read in paths file bufferedreader breader = new bufferedreader(new inputstreamreader( stream, charset.forname("utf-8"))); return breader; }
- right click on project in eclipse. new -> source folder.
- name source folder anything. e.g. cmu_src.
- copy or drag entire cmu directory in cmu_src. make jar.
eclipse don't put resource/assets directories when create jar.
Comments
Post a Comment