java - Unable to import project in eclipse: "Impossible to find or load the main class" -
i've imported this project on eclipse workspace. after time spent find correct jar dependencies, i've tried run project, says me it's impossible find or load main class.
to import project, downloaded , imported on eclipse using file -> import. there problems dependencies (there classes eclipse couldn't find), downloaded jars of these dependencies , included in project.
this code of mainclass
:
package com.yeokhengmeng.docstopdfconverter; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstream; import java.io.outputstream; import org.kohsuke.args4j.cmdlineexception; import org.kohsuke.args4j.cmdlineparser; import org.kohsuke.args4j.option; public class mainclass{ public static final string version_string = "\ndocs pdf converter version 1.7 (8 dec 2013)\n\nthe mit license (mit)\ncopyright (c) 2013-2014 yeo kheng meng"; public enum doc_type { doc, docx, ppt, pptx, odt } public static void main(string[] args){ converter converter; try{ converter = processarguments(args); } catch (exception e){ system.out.println("\n\ninput\\output file not specified properly."); return; } if(converter == null){ system.out.println("unable determine type of input file."); } else { try { converter.convert(); } catch (exception e) { e.printstacktrace(); } } } public static converter processarguments(string[] args) throws exception{ commandlinevalues values = new commandlinevalues(); cmdlineparser parser = new cmdlineparser(values); converter converter = null; try { parser.parseargument(args); boolean version = values.version; if(version){ system.out.println(version_string); system.exit(0); } string inpath = values.infilepath; string outpath = values.outfilepath; boolean shouldshowmessages = values.verbose; if(inpath == null){ parser.printusage(system.err); throw new illegalargumentexception(); } if(outpath == null){ outpath = changeextensiontopdf(inpath); } string lowercaseinpath = inpath.tolowercase(); inputstream instream = getinfilestream(inpath); outputstream outstream = getoutfilestream(outpath); if(values.type == null){ if(lowercaseinpath.endswith("doc")){ converter = new doctopdfconverter(instream, outstream, shouldshowmessages, true); } else if (lowercaseinpath.endswith("docx")){ converter = new docxtopdfconverter(instream, outstream, shouldshowmessages, true); } else if(lowercaseinpath.endswith("ppt")){ converter = new ppttopdfconverter(instream, outstream, shouldshowmessages, true); } else if(lowercaseinpath.endswith("pptx")){ converter = new pptxtopdfconverter(instream, outstream, shouldshowmessages, true); } else if(lowercaseinpath.endswith("odt")){ converter = new odttopdf(instream, outstream, shouldshowmessages, true); } else { converter = null; } } else { switch(values.type){ case doc: converter = new doctopdfconverter(instream, outstream, shouldshowmessages, true); break; case docx: converter = new docxtopdfconverter(instream, outstream, shouldshowmessages, true); break; case ppt: converter = new ppttopdfconverter(instream, outstream, shouldshowmessages, true); break; case pptx: converter = new pptxtopdfconverter(instream, outstream, shouldshowmessages, true); break; case odt: converter = new odttopdf(instream, outstream, shouldshowmessages, true); break; default: converter = null; break; } } } catch (cmdlineexception e) { // handling of wrong arguments system.err.println(e.getmessage()); parser.printusage(system.err); } return converter; } public static class commandlinevalues { @option(name = "-type", aliases = "-t", required = false, usage = "specifies doc converter. leave blank let program decide input extension.") public doc_type type = null; @option(name = "-inputpath", aliases = {"-i", "-in", "-input"}, required = false, metavar = "<path>", usage = "specifies path input file.") public string infilepath = null; @option(name = "-outputpath", aliases = {"-o", "-out", "-output"}, required = false, metavar = "<path>", usage = "specifies path output pdf.") public string outfilepath = null; @option(name = "-verbose", aliases = {"-v"}, required = false, usage = "to see intermediate processing messages.") public boolean verbose = false; @option(name = "-version", aliases = {"-ver"}, required = false, usage = "to view version code.") public boolean version = false; } //from http://stackoverflow.com/questions/941272/how-do-i-trim-a-file-extension-from-a-string-in-java public static string changeextensiontopdf(string originalpath) { // string separator = system.getproperty("file.separator"); string filename = originalpath; // // remove path upto filename. // int lastseparatorindex = originalpath.lastindexof(separator); // if (lastseparatorindex == -1) { // filename = originalpath; // } else { // filename = originalpath.substring(lastseparatorindex + 1); // } // remove extension. int extensionindex = filename.lastindexof("."); string removedextension; if (extensionindex == -1){ removedextension = filename; } else { removedextension = filename.substring(0, extensionindex); } string addpdfextension = removedextension + ".pdf"; return addpdfextension; } protected static inputstream getinfilestream(string inputfilepath) throws filenotfoundexception{ file infile = new file(inputfilepath); fileinputstream istream = new fileinputstream(infile); return istream; } protected static outputstream getoutfilestream(string outputfilepath) throws ioexception{ file outfile = new file(outputfilepath); try{ //make directories specified outfile.getparentfile().mkdirs(); } catch (nullpointerexception e){ //ignore error since means not parent directories } outfile.createnewfile(); fileoutputstream ostream = new fileoutputstream(outfile); return ostream; } }
there error in class, neither in other classes of project.
because never included class in packaged jar.
as project uses maven. can see dependencies (jars) available in pom.xml.
https://github.com/yeokm1/docs-to-pdf-converter/blob/master/docs-to-pdf-converter/pom.xml
just import project maven ide.
mvn clean install
sample output running eclipse or normal maven repl :
------------------------------------------------------- t e s t s ------------------------------------------------------- results : tests run: 0, failures: 0, errors: 0, skipped: 0 [info] [info] --- maven-jar-plugin:2.3.2:jar (default-jar) @ docs-to-pdf-converter --- [info] building jar: /home/docs-to-pdf-converter/target/docs-to-pdf-converter-1.8.jar [info] [info] --- maven-install-plugin:2.3.1:install (default-install) @ docs-to-pdf-converter --- [info] installing /home/docs-to-pdf-converter/target/docs-to-pdf-converter-1.8.jar /home/**/.m2/repository/docs-to-pdf-converter/docs-to-pdf-converter/1.8/docs-to-pdf-converter-1.8.jar [info] installing /home/docs-to-pdf-converter/pom.xml /home/**/.m2/repository/docs-to-pdf-converter/docs-to-pdf-converter/1.8/docs-to-pdf-converter-1.8.pom [info] ------------------------------------------------------------------------ [info] build success [info] ------------------------------------------------------------------------ [info] total time: 2.346s [info] finished at: fri aug 18 06:18:31 edt 2017 [info] final memory: 23m/475m [info] ------------------------------------------------------------------------
my environment :
java : 1.8.0_141 , maven : apache maven 3.0.5
Comments
Post a Comment