Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: the application runs inside Eclipse, but dont run as a jar from cmd

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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)

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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
    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.

  5. #5
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: the application runs inside Eclipse, but dont run as a jar from cmd

    Quote Originally Posted by copeg View Post
    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..

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: the application runs inside Eclipse, but dont run as a jar from cmd

    Quote Originally Posted by copeg View Post
    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.
    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
    ...
    this.getClass().getResorceAsStream("/xsd/schema.xsd")

     
    .....
    <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
    Last edited by beruska; October 12th, 2011 at 03:59 PM.

  8. #8
    Junior Member
    Join Date
    Oct 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

Similar Threads

  1. Replies: 24
    Last Post: August 4th, 2014, 12:49 PM
  2. Program Runs in Eclipse but Not When Exported
    By Pantheon8 in forum Java IDEs
    Replies: 2
    Last Post: August 17th, 2011, 05:57 PM
  3. Beginners Eclipse Tutorial. How to run first java application on Eclipse?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 13
    Last Post: June 24th, 2011, 12:26 AM
  4. runs once only
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 03:31 AM