Load data into Java GUI [closed] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with JavaDealing with “Xerces hell” in Java/Maven?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
If 'B is more likely given A', then 'A is more likely given B'
What causes the vertical darker bands in my photo?
How much radiation do nuclear physics experiments expose researchers to nowadays?
Antler Helmet: Can it work?
Why are there no cargo aircraft with "flying wing" design?
How do I keep my slimes from escaping their pens?
What makes black pepper strong or mild?
ListPlot join points by nearest neighbor rather than order
Output the ŋarâþ crîþ alphabet song without using (m)any letters
Why was the term "discrete" used in discrete logarithm?
Examples of mediopassive verb constructions
What do you call a plan that's an alternative plan in case your initial plan fails?
What is a Meta algorithm?
What is the correct way to use the pinch test for dehydration?
Is high blood pressure ever a symptom attributable solely to dehydration?
Best practices for giving outside developer SSH access?
Gastric acid as a weapon
Why is black pepper both grey and black?
How do I mention the quality of my school without bragging
Is 1 ppb equal to 1 μg/kg?
How to find all the available tools in macOS terminal?
3 doors, three guards, one stone
When -s is used with third person singular. What's its use in this context?
Load data into Java GUI [closed]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I convert a String to an int in Java?Creating a memory leak with JavaDealing with “Xerces hell” in Java/Maven?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am working on a Java GUI which requires data to be read from an XML file. Ultimately i want to deliver a single .exe or .jar file where all the things you need are stored. These databases should get automatically parsed.
My question is: Where and in which format should I store the files so that they are always found automatically?
It should be as if the XML files are written in the sourcecode, but I don't think that this would be a good approach to this problem.
Thanks in advance.
java xml javafx
closed as too broad by DanielBarbarian, greg-449, Matteo Baldi, EdChum, Mark Rotteveel Mar 22 at 9:39
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am working on a Java GUI which requires data to be read from an XML file. Ultimately i want to deliver a single .exe or .jar file where all the things you need are stored. These databases should get automatically parsed.
My question is: Where and in which format should I store the files so that they are always found automatically?
It should be as if the XML files are written in the sourcecode, but I don't think that this would be a good approach to this problem.
Thanks in advance.
java xml javafx
closed as too broad by DanielBarbarian, greg-449, Matteo Baldi, EdChum, Mark Rotteveel Mar 22 at 9:39
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I am working on a Java GUI which requires data to be read from an XML file. Ultimately i want to deliver a single .exe or .jar file where all the things you need are stored. These databases should get automatically parsed.
My question is: Where and in which format should I store the files so that they are always found automatically?
It should be as if the XML files are written in the sourcecode, but I don't think that this would be a good approach to this problem.
Thanks in advance.
java xml javafx
I am working on a Java GUI which requires data to be read from an XML file. Ultimately i want to deliver a single .exe or .jar file where all the things you need are stored. These databases should get automatically parsed.
My question is: Where and in which format should I store the files so that they are always found automatically?
It should be as if the XML files are written in the sourcecode, but I don't think that this would be a good approach to this problem.
Thanks in advance.
java xml javafx
java xml javafx
asked Mar 22 at 8:21
lospolloslospollos
254
254
closed as too broad by DanielBarbarian, greg-449, Matteo Baldi, EdChum, Mark Rotteveel Mar 22 at 9:39
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by DanielBarbarian, greg-449, Matteo Baldi, EdChum, Mark Rotteveel Mar 22 at 9:39
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If these files shall only be read, you may store them as resources in the class path. If the resource file is in the same directory as your class you may access the resource from within instances of that class like:
final URL myResource = getClass().getResource(nameOfFile);
final InputStream myResourceStream = getClass().getResourceAsStream(nameOfFile);
Static access is possible like:
final URL myResource = MyClass.class.getResource(nameOfFile);
The nameOfFile may also contain a path to navigate withing the package structure:
final Resource myResource = getClass().getResource("subpackage/data.xml");
final Resource myResource = getClass().getResource("/com/myCompany/somePackage/data.xml");
And by the way: i recommend to use the java.nio.* classes to access files. One huge benefit is that this allows you to set custom file system implementations, if needed.
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If these files shall only be read, you may store them as resources in the class path. If the resource file is in the same directory as your class you may access the resource from within instances of that class like:
final URL myResource = getClass().getResource(nameOfFile);
final InputStream myResourceStream = getClass().getResourceAsStream(nameOfFile);
Static access is possible like:
final URL myResource = MyClass.class.getResource(nameOfFile);
The nameOfFile may also contain a path to navigate withing the package structure:
final Resource myResource = getClass().getResource("subpackage/data.xml");
final Resource myResource = getClass().getResource("/com/myCompany/somePackage/data.xml");
And by the way: i recommend to use the java.nio.* classes to access files. One huge benefit is that this allows you to set custom file system implementations, if needed.
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
add a comment |
If these files shall only be read, you may store them as resources in the class path. If the resource file is in the same directory as your class you may access the resource from within instances of that class like:
final URL myResource = getClass().getResource(nameOfFile);
final InputStream myResourceStream = getClass().getResourceAsStream(nameOfFile);
Static access is possible like:
final URL myResource = MyClass.class.getResource(nameOfFile);
The nameOfFile may also contain a path to navigate withing the package structure:
final Resource myResource = getClass().getResource("subpackage/data.xml");
final Resource myResource = getClass().getResource("/com/myCompany/somePackage/data.xml");
And by the way: i recommend to use the java.nio.* classes to access files. One huge benefit is that this allows you to set custom file system implementations, if needed.
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
add a comment |
If these files shall only be read, you may store them as resources in the class path. If the resource file is in the same directory as your class you may access the resource from within instances of that class like:
final URL myResource = getClass().getResource(nameOfFile);
final InputStream myResourceStream = getClass().getResourceAsStream(nameOfFile);
Static access is possible like:
final URL myResource = MyClass.class.getResource(nameOfFile);
The nameOfFile may also contain a path to navigate withing the package structure:
final Resource myResource = getClass().getResource("subpackage/data.xml");
final Resource myResource = getClass().getResource("/com/myCompany/somePackage/data.xml");
And by the way: i recommend to use the java.nio.* classes to access files. One huge benefit is that this allows you to set custom file system implementations, if needed.
If these files shall only be read, you may store them as resources in the class path. If the resource file is in the same directory as your class you may access the resource from within instances of that class like:
final URL myResource = getClass().getResource(nameOfFile);
final InputStream myResourceStream = getClass().getResourceAsStream(nameOfFile);
Static access is possible like:
final URL myResource = MyClass.class.getResource(nameOfFile);
The nameOfFile may also contain a path to navigate withing the package structure:
final Resource myResource = getClass().getResource("subpackage/data.xml");
final Resource myResource = getClass().getResource("/com/myCompany/somePackage/data.xml");
And by the way: i recommend to use the java.nio.* classes to access files. One huge benefit is that this allows you to set custom file system implementations, if needed.
edited Mar 22 at 10:58
answered Mar 22 at 8:35
AmadánAmadán
28229
28229
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
add a comment |
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
Thanks, this works fine when executed in my IDE, but does not work when building an .exe artifact and executing the .exe program (it cannot find the directory). Do you know a solution do this problem as well?
– lospollos
Mar 27 at 8:31
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
@lospollos I am not at all familiar with creating executables from java projects. Maybe your process does not include the resources into your compilation target. Maybe you missed an option for that? Or maybe you need to include a second file with your .exe?
– Amadán
Mar 27 at 11:54
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
Lets forget the .exe thing and assume I want to build a jar application. Do you know how I could set the path in the sourcecode in order to load the databases when delivering my tool? E.g. the databases are in a specific folder and the jar file is in another
– lospollos
Mar 27 at 15:11
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
If you mean providing the configuration of DB access, then a java properties file as resource may be a good approach. If you mean setting something like the windows PATH variable: for heaven's sake don't! The system configuration is something your application should not take control over.
– Amadán
Apr 1 at 7:59
add a comment |