Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Making an executable jar that includes a properties xml
Making an executable jar that includes a properties xml [message #336254] Wed, 03 June 2009 17:59 Go to next message
Lenny Wintfeld is currently offline Lenny WintfeldFriend
Messages: 11
Registered: July 2009
Junior Member
In Eclipse 3.4.0

I'm making an executable jar of one of my projects but the properties xml
file that's part of the project is not included in the jar and so the jar
will not run.

I'm using File->Export->Java->Runnable JAR File to make the jar

The properties xml ".\myMailProps.xml" is used by my program using the
regular java.util.Properties class's methods loadFromXML and storeToXML
calls and is stored in my programs root directory.

Any idea how I can get eclipse to make an executable jar for me that
includes this (and possibly some other) necessary files in the jar? The
program runs fine under eclipse, now its just a matter of making it easily
distributable.

Thanks in advance for any help.

Lenny Wintfeld
Re: Making an executable jar that includes a properties xml [message #336266 is a reply to message #336254] Thu, 04 June 2009 12:57 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If your property is needed, how are you loading it? Are you using
getResourceAsStream(*), which is the common way to get resources from
your classpath/jars?

If that's the case, then put your properties file in the root of your
<project>/src folder and it will be included in the jar as a resource.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Making an executable jar that includes a properties xml [message #336272 is a reply to message #336266] Thu, 04 June 2009 18:32 Go to previous messageGo to next message
Lenny Wintfeld is currently offline Lenny WintfeldFriend
Messages: 11
Registered: July 2009
Junior Member
Here's sketch of what I'm doing

public class MyClass
{
final Properties myProps; //field of class
.
.
public MyClass() //constructor
{
myProps = new Properties();
//try block omitted
myProps.loadFromXML(new FileInputStream("./myMailProps.xml"));
.
.
//do stuff including many properties gets
metfn = myProps.getProperty("Member Email Body");

}


//method of the same class
public void saveAllFields()
{
FileOutputStream fos = new FileOutputStream (new
File("./myMailProps.xml"));
myProps.setProperty("Mem Email Adresses", memFileName );
//Set many more properties
.
.
myProps.storeToXML(fos,"");

}

}//myClass

My directory structure in the eclipse ....\workspace is

<projectName>/src/<packageName>/all .java files here
<projectName>/bin/<packageName>/all .class files here

and the myProps.xml file(using ./myMailProps.xml as shown above) is in
<projectName>/myMailProps.xml

Using your reply as a hint, with windows explorer I put copies of the file
in each of the subdirs shown above (only one at a time). But it doesn't
result in the xml being put in to the jar.

Hope this will help you to help me.

Thanks,
Lenny
Re: Making an executable jar that includes a properties xml [message #336273 is a reply to message #336272] Thu, 04 June 2009 19:06 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

If you need to talk about your prop file as a File, then you can't
include it in your jar. If you load it from a resource, then you can
include it in your jar. See
http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808 -property.html


I would use getClass().getResourceAsStream(*) and then you can put your
properties file in your /src folder somewhere.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Making an executable jar that includes a properties xml [message #336282 is a reply to message #336273] Fri, 05 June 2009 00:29 Go to previous message
Lenny Wintfeld is currently offline Lenny WintfeldFriend
Messages: 11
Registered: July 2009
Junior Member
Thanks for the reference, I'll see if I can work it into the code. I mean
the properties file to be occasionally edited by hand, that's why I chose
an XML. But this may work out.

--Lenny
Previous Topic:Editors updating command enablement
Next Topic:[CommonNavigator] hideLinkWithEditorAction
Goto Forum:
  


Current Time: Fri Mar 29 09:52:59 GMT 2024

Powered by FUDForum. Page generated in 0.09880 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top