the application runs inside Eclipse, but dont run as a jar from cmd
Hello,
I have an applications, and it runs correct inside Eclipse (I use build.xml to compile, generate jar, run) and everything seems ok. But when I want to run my generated jar from cmd, i have some problems, and the jar does not run. So, I wonder if it possible to run IDE by some "command" and config somehow ant to run my jar properly?
I hope you'll understand what I mean.
Thank you
Re: the application runs inside Eclipse, but dont run as a jar from cmd
What exception do you get when you try to run the jar? Does your manifest file specify the main class? See the following:
Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)
Re: the application runs inside Eclipse, but dont run as a jar from cmd
the exception is that the stream I get from getResourceAsStream is null, (it has to be an xml scheme/xsd/), thats why I cant parse the xml then.... The manifest is ok, The main-class is ok, I've set class-path too, to my xsd file, I save it in a folder xsd/schema.xsd, and the Class-Path: xsd/schema.xsd. Is it possible because I run my jar outside Eclipse?
Re: the application runs inside Eclipse, but dont run as a jar from cmd
Quote:
the exception is that the stream I get from getResourceAsStream is null
Is the resource packaged into the jar (you can unpack the jar and look)? Eclipse automatically does this for you...if you are using ant you must make sure all the necessary files are packaged appropriately within the jar (not just the .class files). Eclipse has an export utility to package everything into a runnable jar (right click project, go to export, and select runnable jar), so unless you are using ant for anything other than compilation and creating the jar, this might be an easier approach.
Re: the application runs inside Eclipse, but dont run as a jar from cmd
Quote:
Originally Posted by
copeg
Is the resource packaged into the jar (you can unpack the jar and look)? Eclipse automatically does this for you...if you are using ant you must make sure all the necessary files are packaged appropriately within the jar (not just the .class files). Eclipse has an export utility to package everything into a runnable jar (right click project, go to export, and select runnable jar), so unless you are using ant for anything other than compilation and creating the jar, this might be an easier approach.
Yup I know, so when I unpack my jar i have the folder xsd/schema.xsd, thus the schema is inside my of my jar. I use ant for others things, so I cant just export it :((. I woud like to, but..
Re: the application runs inside Eclipse, but dont run as a jar from cmd
What is the path you pass to getResourceAsStream, and the path to your xsd file within your jar? At this point, it might help to post an SSCCE that demonstrates this issue.
Re: the application runs inside Eclipse, but dont run as a jar from cmd
Quote:
Originally Posted by
copeg
What is the path you pass to getResourceAsStream, and the path to your xsd file within your jar? At this point, it might help to post an SSCCE that demonstrates this issue.
Code :
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
factory.setIgnoringComments(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(xsd);
}
});
builder.setErrorHandler(new ErrHandler());
Document doc = builder.parse(xml);
...
I get InputStream like this
Code :
...
this.getClass().getResorceAsStream("/xsd/schema.xsd")
Code :
.....
<manifest>
<attribute name="Main-class" value="validation.Parser"/>
<attribute name="Class-Path" value="xsd/schema.xsd"/>
</manifest
Path to xsd in my jar is xsd/schema.xsd
Re: the application runs inside Eclipse, but dont run as a jar from cmd
Well, The problem is in getResourceAsStream. When I change the path from xsd/schema.xsd to ../schema.xsd it works when I compile it Ctrl+F11, but it doesnt work when I use Ant, is it possible because of something wrong is with my classpath in manifest?