How to read properties stored in jar file
Hello
I got one question.
I created properties file in my project, which contains some texts for panels. When I start application from JBuilder all works fine. This priperies file is stored in path "cmt/locales/CMTModule.properties".
Problem is only in case I created jar file in which is this mentioned properties file. When I run through doubleclick my file ins't loaded.
My procedure for load resource is follow:
ResourceBundle res = null;
private void initLocales() {
String packageName;
String className;
String bundleName = null;
String name = null;
int index;
try {
packageName = this.getClass().getPackage().getName().toLowerCase();
className = this.getClass().getName().toLowerCase();
index = className.lastIndexOf(".");
if (index > -1) {
className = className.substring(index + 1);
bundleName = packageName;
bundleName = bundleName + ".locales.";
bundleName = bundleName + className;
res = ResourceBundle.getBundle(bundleName);
res = new PropertyResourceBundle(this.getClass().getResourceAsStream("locales/"+ className + ".properties"));
} catch (Exception exception) {
System.out.println("Error to get local settings");
try {
locales = new Locales(res);
} catch (Exception exception) {
exception.printStackTrace();
}Whats wrong ?
Thank You Very Much
Problem was in case insensivite, because I'm convert class name to lower case. I only removed function toLowerCase().
I replace these lines
packageName = this.getClass().getPackage().getName().toLowerCase();
className = this.getClass().getName().toLowerCase();with
packageName = this.getClass().getPackage().getName();
className = this.getClass().getName();Thanks
Similar Messages
-
How to install a Application in *.jar file format?
How to install a Application in *.jar file format?
I have taken the *.jar file into the device into media folder. but device is not recognizing the file format
could some one plz provide some suggestion to proceed with this?
Thanks
Mohamed JaveedI'm having the same problem. I've put .jar into the 'system' folder but that doesn't seem to make the program work neverless see it on my device. Help.
-
How to read contents of a property file sequentially
hello all,
please can any one tell me how to read contents of a property file sequentially.
i saw most of the classes provided by JAVA API, which get All keys and there return type is enumeration which dosent preserve , or may the getKeys() method of those classes do not preserve the sequential order.
Kindly do let me know if anyone has done this before.
Thanks.The best solution is that you redesign your program so that it does not depend on the order of the entries in the properties file.
If you really want to stay with your design, you will have to read the properties file yourself, line by line, just like you would read any other text file, and parse the content of each line yourself.
BufferedReader in = new BufferedReader(new FileReader("stuff.properties"));
String line;
while ((line = in.readLine()) != null) {
// Parse the line, use e.g. String.split() to split it around the '='
in.close(); -
I have a main fillable form. From this main form the user may need additional forms. I want to create checkboxes that link to these additional forms. This part I believe I know how to do (Properties/Actions/Open a File). What I want to add is a javascript to the checkbox that when the new file (or form) opens some of the data (the repetitive data like name, date, etc.) from the main form is placed into the form opened where the same form fields exist. Is this possible?
Yes, but then it all has to be done using a script. You can't use the built-in Open A File command.
-
How do I deploy an external JAR file
Hello,
How do I deploy an external JAR file?
I am grateful for every hint.Hi Manuel,
If you read my blog mentioned in the beginning of the thread, you will note that such solution is not supported in our engine due to number of reasons.
Please, read the blog and use application library shared among these two applications. You will achieve the same effect. Please note that the using application will need run and deploy-time dependencies to the shared library.
You should not add files to any of the folders manually or manipulate engine's classpath in such situations.
Best Regards,
Georgi -
How to read MG1, MGU, SG1, SGU files?
I have copies of Band in a Box and Aebersold music software, from an older PC.
How to read MG1, MGU, SG1, SGU files on my MacBook Air?
Many thanks, AntoineI believe in Linux/Unix, everything is treated as a file descriptor, be it a disk, socket, hardware device or an actual file. Since Java will simply call the appropriate method (length() for example) on the descriptor, I would imagine it would be up to the operating system to determine what to return. If I ask for the length() of a socket, I'm not sure what it would return. The bytes not flushed in the buffer? Total transmitted? Some random uid? I'm sure it is defined somewhere but the behavior may not be what you expect. See if you can use a 'vanilla' command-line method to get the file length from that device. If it too returns zero, you know it's not your program.
- Saish -
How to read the data from Excel file and Store in XML file using java
Hi All,
I got a problem with Excel file.
My problem is how to read the data from Excel file and Store in XML file using java excel api.
For getting the data from Excel file what are all the steps i need to follow to get the correct result.
Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
Thanks & Regards,
Sreenu,
[email protected],
india,If you want someone to do your work, please have the courtesy to provide payment.
http://www.rentacoder.com -
How can I get a single jar file with NetBeans?
How can I get a single jar file with NetBeans?
When I create the project I get these files:
dist/lib/libreria1.jar
dist/lib/libreria2.jar
dist/software.jar
The libraries that have been imported to create the project are in separate folders:
libreria1/libreria1.jar
libreria2/libreria2.jar
libreria1, libreria2, dist folders are all located inside the project folder.
I added the following code to the build.xml:
<target name="-post-jar">
<jar jarfile="dist/software.jar">
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="dist/lib/libreria1.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/libreria2.jar" excludes="META-INF/*" />
<manifest>
<attribute name="Main-Class" value="pacco.classeprincipale"/>
</manifest>
</jar>
</target>
Of course there is also the project folder:
src/pacco/classeprincipale.form
src/pacco/classeprincipale.java
Can you tell me what is wrong? The error message I get is as follows:
C:...\build.xml:75: Problem creating jar: archive is not a ZIP archive BUILD FAILED (total time: 2 seconds)This is not a NetBeans forum, it is a JDeveloper forum. You might want to try http://forums.netbeans.org/. I also saw your other question - try looking in the New to Java forum: New To Java
-
How to create and use library JAR files with command-line tools?
Development Tools -> General Questions:
I am trying to figure out how to put utility classes into JAR files and then compile and run applications against those JAR files using the command-line javac, jar, and java tools. I am using jdk1.7.0_17 on Debian GNU/Linux 6.0.7.
I have posted a simple example with one utility class, one console application class, and a Makefile:
http://holgerdanske.com/users/dpchrist/java/examples/jar-20130520-2134.tar.gz
Here is a console session:
2013-05-20 21:39:01 dpchrist@desktop ~/sandbox/java/jar
$ cat src/com/example/util/Hello.java
package com.example.util;
public class Hello {
public static void hello(String arg) {
System.out.println("hello, " + arg);
2013-05-20 21:39:12 dpchrist@desktop ~/sandbox/java/jar
$ cat src/com/example/hello/HelloConsole.java
package com.example.hello;
import static com.example.util.Hello.hello;
public class HelloConsole {
public static void main(String [] args) {
hello("world!");
2013-05-20 21:39:21 dpchrist@desktop ~/sandbox/java/jar
$ make
rm -f hello
find . -name '*.class' -delete
javac src/com/example/util/Hello.java
javac -cp src src/com/example/hello/HelloConsole.java
echo "java -cp src com.example.hello.HelloConsole" > hello
chmod +x hello
2013-05-20 21:39:28 dpchrist@desktop ~/sandbox/java/jar
$ ./hello
hello, world!I believe I am looking for:
1. Command-line invocation of "jar" to put the utility class bytecode file (Hello.class) into a JAR?
2. Command-line invocation of "javac" to compile the application (HelloConsole.java) against the JAR file?
3. Command-line invocation of "java" to run the application (HelloConsole.class) against the JAR file?
I already know how t compile the utility class file.
Any suggestions?
TIA,
DavidI finally figured it out:
1. All name spaces must match -- identifiers, packages, file system, JAR contents, etc..
2. Tools must be invoked from specific working directories with specific option arguments, all according to the project name space.
My key discovery was that if the code says
import com.example.util.Hello;then the JAR must contain
com/example/util/Hello.classand I must invoke the compiler and interpreter with an -classpath argument that is the full path to the JAR file
-classpath ext/com/example/util.jarThe code is here:
http://holgerdanske.com/users/dpchrist/java/examples/jar-20130525-1301.tar.gz
Here is a console session that demonstrates building and running the code two ways:
1. Compiling the utility class into bytecode, compiling the application class against the utility bytecode, and running the application bytecode against the utility bytecode.
2. Putting the (previously compiled) utility bytecode into a JAR and running the application bytecode against the JAR. (Note that recompiling the application against the JAR was unnecessary.)
(If you don't know Make, understand that the working directory is reset to the initial working directory prior to each and every command issued by Make):
2013-05-25 14:02:47 dpchrist@desktop ~/sandbox/java/jar
$ cat apps/com/example/hello/Console.java
package com.example.hello;
import com.example.util.Hello;
public class Console {
public static void main(String [] args) {
Hello.hello("world!");
2013-05-25 14:02:55 dpchrist@desktop ~/sandbox/java/jar
$ cat libs/com/example/util/Hello.java
package com.example.util;
public class Hello {
public static void hello(String arg) {
System.out.println("hello, " + arg);
2013-05-25 14:03:03 dpchrist@desktop ~/sandbox/java/jar
$ make
rm -rf bin ext obj
mkdir obj
cd libs; javac -d ../obj com/example/util/Hello.java
mkdir bin
cd apps; javac -d ../bin -cp ../obj com/example/hello/Console.java
cd bin; java -cp .:../obj com.example.hello.Console
hello, world!
mkdir -p ext/com/example
cd obj; jar cvf ../ext/com/example/util.jar com/example/util/Hello.class
added manifest
adding: com/example/util/Hello.class(in = 566) (out= 357)(deflated 36%)
cd bin; java -cp .:../ext/com/example/util.jar com.example.hello.Console
hello, world!
2013-05-25 14:03:11 dpchrist@desktop ~/sandbox/java/jar
$ tree -I CVS .
|-- Makefile
|-- apps
| `-- com
| `-- example
| `-- hello
| `-- Console.java
|-- bin
| `-- com
| `-- example
| `-- hello
| `-- Console.class
|-- ext
| `-- com
| `-- example
| `-- util.jar
|-- libs
| `-- com
| `-- example
| `-- util
| `-- Hello.java
`-- obj
`-- com
`-- example
`-- util
`-- Hello.class
19 directories, 6 filesHTH,
David -
How to read the complete path in file upload UI
Hi,
I want to know how to read the complete path in file upload UI in java web dynpro.
I have created 1 file upload UI and than when i do browse and select some file say small.jpg from my local PC, desktop , its path is coming in file upload UI like E:\small.jpg,
I want to know how to get this path in java webdynpro code.
please let me know..Hi Satyam,
In webdynpro java, first file stores in server location then it reads from server.
Create a button with upload and write this code OnAction
Resource is the attribute name in context of type com.sap.ide.webdynpro.uielementdefinitions.Resource, this attribute is for Resource property for Upload UI Element.
Then in OnAction of button
InputStream text = null;
int temp=0;
try{
File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
}catch(Exception e){
e.printStackTrace();
//@@end
Regards,
Pradeep
Edited by: pradeep_546 on May 11, 2011 12:22 PM -
How to handle 2 or more .jar files with an applet
Hey out there
I have created an ftpClient application that uses "jakarta ftpClient". It works fine as an JFrame application � But when I converted the Application into an JApplet I get the following Exception:
java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClient
I have bundled the main application into a .jar file (Application,jar). But I don't know how to handle the 2 jakarta .jar files with my JApplet??
I Tried to append the 2 jakarta .jar files to the Application,jar with the following code:
jar cvf Application.jar 1.class 2.class�. commons-net-1.4.1.jar jakarta-oro-2.0.8.jar
But with the same result / Exception (I have signed the Jar file!)
Can anyone help meHi i have a question with your application can you down- or upload more files at the same time? Because i'm having problems with my ftp application.
Here is the link with my problem maybe you can help me. I will be very pleased when you can help me.
http://forum.java.sun.com/thread.jspa?threadID=5162042&tstart=0
Thx
Satanduvel -
How to read and upload microsoft word file into database using forms9i
Hi,
How to read and upload microsoft word file into oracle database using forms9i. I appretiate if anyone can send me example or atleast a sujjetion.
Thanks in advance
Mahesh RagineniThe webutil package includes the ability up upload from the client to the database. See otn.oracle.com/products/forms and click on webutil for more details.
Regards
Grant Ronald
Forms Product Management -
How to read properties file(key-value) in OSB?
Hi
I have a scenario in which I have to read some properties(key-value) from a file. Earlier whole code was developed in java and its easy to read properties file in java.
But now need to implement this in OSB and performance is very critical in this project.
I followed DVM approached defined in
http://blogs.oracle.com/christomkins/2010/02/domain_value_maps_in_oracle_se.html and http://blogs.oracle.com/christomkins/2010/02/domain_value_maps_in_oracle_se.html
But it did not work. I have hundreds of properties(key-value pairs) to read and need pass them to the business service along with input of proxy service.
What is the best approach for this (Can not go for db call as performance is very critical)?
Thanks
Vibhor$DVM= <dvm name="InterfaceProperties" xmlns:ns1="http://xmlns.oracle.com/dvm" xmlns="http://xmlns.oracle.com/dvm">
<columns>
<column name="PROPERTY_KEY" qualifier="false" order="1"/>
<column name="PROPERTY_VALUE" qualifier="false" order="1"/>
</columns>
<rows>
<row>
<cell>dealer.locate.default.buypower.link</cell>
<cell>http://www.xyz.com</cell>
</row>
<row>
<cell>dealer.locate.default.unitOfMeasure</cell>
<cell>MILES</cell>
</row>
<row>
<cell>dealer.locate.brand.identifier.nu</cell>
<cell>Nurun</cell>
</row>
<row>
<cell>dealer.locate.brand.identifier.bu</cell>
<cell>Buick</cell>
</row>
<row>
<cell>dealer.locate.brand.identifier.ca</cell>
<cell>Cadillac</cell>
</row>
</rows>
</dvm>
XPATH is- ns1:dvm/ns1:rows[1]/ns1:row[1]/ns1:cell[1]/text()
If I run this xpath in Jdeveloper,its giving me proper output.
Please this as CQuery resource and try to run this xpath on OSB console.
Thanks
Vibhor
Edited by: Vibhor Rastogi on Sep 21, 2010 4:59 AM -
How to read Properties file once and access through the entire application
HI All,
I want to read properties file only once and want to access the property file values in entire application (like i want to access it in a ordinary class)Please do not double-post. Stick with one thread:
http://forum.java.sun.com/thread.jspa?messageID=9678612 -
How to retrieve resources from a jar file ?
Hello,
Currently, I have application classes in a jar file, and all other resources (pictures, properties, and so forth..) in my windows folder. I do not have any problem for using them such way. For example to set an icon to a JFrame I have coded :
f.setIconImage("mypicture.jpg");To make installation easier, I'd like to put my picture into the jar file with the classes. Is it possible ? if so, how should I modify my code to make things work ? Should I specify a special path ?
Thanks for all
GegeThanks a lot, I'm going to try both ways.What both ways? Both replies are about the same thing -- using the classpath to find resources.
The question now is what about if there is the same file
name in the jar file and also in the directory ? Is
there a search hierarchy ?It will find the first one it encounters in the classpath. You shouldn't have 2 resources with the same name in the classpath -- that's just like having two classes with the same package and class name.
Maybe you are looking for
-
I have just purchased a new Mac and want to sync my ipod - previous computer was PC - can I recover tunes from the ipod to the Mac?
-
Firefox 3.6.6 will not allow Windows 7 to log off or shut down
I have a HP DV6 laptop (32 bit) with Windows 7. Firefox 3.6.6. seems to work well but the computer became slow and unresponsive and it will not log off, shut down or restart unless in safe mode. I uninstalled FF 3.6.6. and Adobe Flash 10 and now it w
-
Upgraded from 10.5 to 10.6. IP Printing not working?
Hello, I recently upgraded from 10.5 to 10.6 Snow Leopard and as I knew, our Appletalk Printers no longer showed up. I knew this would be the case and tried adding the printers via IP. I've printed out the spec sheets from the printers to obtain the
-
Hi, This isn't necessarily a major issue, but as a creator and user of LiveCycle forms, I find it to be an annoyance. Does anyone know why after you select a date from the date picker, and then hit Tab, you start over at the beginning/top of the Tab
-
How do I delete a question...
asdf