Execute java code taken from a properties file
I have a requirement to store some java code in the Properties file & use the code inside the program later. Is there a way I can execute this code after I get it from the .properties file which is retrieved using the ResourceBundle?
Example:
File: system.properties
Item_list=blocksBean.menu(QueryValue,request.getContextPath())
Inside my Java program I'm using this..
theBody=codesBean.replaceAll(theBody, "%%menu%%",ResourceBundle.getBundle("system").getString("Item_list"), true);
instead of
theBody=codesBean.replaceAll(theBody, "%%menu%%",blocksBean.menu(QueryValue,request.getContextPath()), true);
This doesn't work because ResourceBundle.getBundle("... returns the value.. which is a string "blocksBean.menu(QueryValue,request.getContextPath())". But what I need is it has to be executed..
blocksBean.menu() returns a string value of html code fetched from the dartabase.
Is there a way I can execute blocksBean.menu() which is retrieved from the .properties file.. If anyone has done it / have an idea on this.. please e-mail me [email protected]
I need something like an eval() in javaScript..
Thanks in advance
-ashok
These boys might have something that will help you:
http://www.beanshell.org/
Good luck
Lee
Similar Messages
-
Java.lang.NullPointerException in the code to read a properties file
I have written the following code to read a properties file...........
<b>
public Property(String fileName)
try
InputStream is = MyClassName.class.getClass().getClassLoader().getResourceAsStream(fileName);
prop.load(is);
is.close();
catch (Exception ex)
System.out.println("The Exception is: " + ex.getMessage());
ex.printStackTrace();
</b>
But this code is giving <b> java.lang.NullPointerException </b> at <b> prop.load(is) </b>
please help me....
regards
Brahmachaitanyahi,
If you are loading a resource (property) file from a jar file you can use
getResourceAsStream("com/test/test.properties").
if the propery file is in outside of your jar file . you can use
Property portalProps = new Property ();
try {
FileInputStream fileInputStream = new FileInputStream("<FilePath + FileName>");
portalProps.load(fileInputStream);
fileInputStream.close();
} catch (IOException e) {
//Log the error
refer the following link for more details
http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html -
Batch file to execute java code
Hi,
I need to write a batch file to execute a sequence of java applications.
The problem i face is in addition to the usual libraries I am also using certain jar files i downloaded like the mail interface etc.
When i just compile a java code using a simple batch file giving the path of the compiler and the java code, it fails citing not knowing the location if the packages.
could anyone please let me know what i need to do. Is there like a skeleton that i might find somewhere for this operationdexterity wrote:
Hi,
I need to write a batch file to execute a sequence of java applications.
The problem i face is in addition to the usual libraries I am also using certain jar files i downloaded like the mail interface etc.
When i just compile a java code using a simple batch file giving the path of the compiler and the java code, it fails citing not knowing the location if the packages.
could anyone please let me know what i need to do. Is there like a skeleton that i might find somewhere for this operationSet the classpath correctly at runtime.
Why do you need the location of your compiler? Are you compiling or running? If you are compiling go look at Ant. -
Error while executing java stored procedure from a pl/sql procedure
We have a requirement where we need to execute JAVA code stored in an Oracle database (Java Stored Procedure). This code uses some JAR files which we have already loaded without any errors in the database.
The class file was also loaded in the database without any errors. But when we execute the method of this class (JAVA code), it gives the following error:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.NoClassDefFoundError
Is there any way of debugging the code and getting to know where exactly the problem is? Or, any tool/software available for doing the same.
Any pointers would be of great help!
Thanks in advanceHi Uday,
My guess is that there is a problem with your java stored procedure that is causing the "ExceptionInInitializer" error to be thrown. According to the javadoc:
is thrown to indicate that an exception occurred during
evaluation of a static initializer or
the initializer for a static variable
Since I didn't see any of your code in your post, I can't help you much more, I'm afraid. Perhaps if you would provide some more details, I may be able to help you some more. I think the following details would be helpful:
1. Complete error message and stack trace you are getting.
2. The section of your java code that you think is causing the problem.
3. Oracle database version you are using.
Good Luck,
Avi. -
Hi i am trying to write a program which reads from a properties file the pr
hi,
this is ayesha.
I am trying to write a program wherein i will be reading the value of a property from a properties file which will be true initially. I want to loop in there till the time when the value of the property is false.
The code is as follows:
public static void main(String[] args) {
ReadingAPropertiesFile propers=new ReadingAPropertiesFile();
propers.ReadingFileRegularly("F:\\ayesha.properties");
public String ReadingFileRegularly(String FilePath){
Properties props = new Properties();
String message;
String filePath=FilePath;
try {
props.load(new FileInputStream(filePath));
message = props.getProperty("ayesha");
boolean theValue = Boolean.parseBoolean(message);
while(theValue){
System.out.println("trueeeeeeeeeeeeeeeeeeeeeee");
Thread.sleep(60000);
ReadingFileRegularly(filePath);
catch(Exception ex){
ex.printStackTrace();
String messagean="something";
return messagean;
The contents of ayesha.properties are :
ayesha=true
After 5 minutes it will be set to false so i want to loop in there till the value of ayesha=false at which time i will return
But i dont know how to loop in there for that time:
while(theValue) ?????????????/ what after this???????????
Any suggestons are awaited.ayeshaparween wrote:
hi,
this is ayesha.
I am trying to write a program wherein i will be reading the value of a property from a properties file which will be true initially. I want to loop in there till the time when the value of the property is false.
The code is as follows:
public static void main(String[] args) {
ReadingAPropertiesFile propers=new ReadingAPropertiesFile();
propers.ReadingFileRegularly("F:\\ayesha.properties");
public String ReadingFileRegularly(String FilePath){
Properties props = new Properties();
String message;
String filePath=FilePath;
try {
props.load(new FileInputStream(filePath));
message = props.getProperty("ayesha");
boolean theValue = Boolean.parseBoolean(message);
while(theValue){
System.out.println("trueeeeeeeeeeeeeeeeeeeeeee");
Thread.sleep(60000);
ReadingFileRegularly(filePath);//recursive call this is a bad idea might result in stack overflow error
catch(Exception ex){
ex.printStackTrace();
String messagean="something";
return messagean;
The contents of ayesha.properties are :
ayesha=true
After 5 minutes it will be set to false so i want to loop in there till the value of ayesha=false at which time i will return
But i dont know how to loop in there for that time:
while(theValue) ?????????????/ what after this???????????
Any suggestons are awaited.I think you better rethink your design , do not use recursion, I would normally use a loop like you did but without loading the content of the file each time, I would use File.l lastModified() method and compare with previous results from this method to see if the file was modified. Then if it was modified then load the new File and check if the property value has changed. -
Hi experts,
I'd like to execute some Java code after a successful login. I guess I could write a custom login module or use a WD Java iView to do this but a "better" solution may exist.
Regards,
PierreCustomizing your login module is probably your best bet. As soon as you're user is authenticated, you can execute your custom Java code.
From my experience, I have not seen an easier / cleaner way to capture that event.
Regards,
Tom -
Retreiving only particular keys from a properties file
hello friends,
can someone kindly tell me , is there any way to retreive only particular keys from a properties file .
for e.g the file is as follows
abc.properties
ad_1 = "hello"
ad_1_fg = "bye"
ad_1_hj = "dfd"
ad_1_jk = "sdfsdf"
bk_2_jk = "sdfdsf"
bk_2_lk = "klklk"
so lets say at run time , i get the key ad_1 , and i am told to retreive all the keys from the properties file starting only with ad_1, then how do i do it.
I tried using ResourceBundl,PropertyResourceBundle, but they all get all the keys, and tehre is no way to specify within them that get only keys with particular format.
please do help meRetrieve all the properties, and then loop over them
looking for those whose names match the pattern you
need.hello jverd thanks for your quick response, i was thinking the same, but lets say i retreive all keys, then how do i match them to my pattern, i mean if some keys is like this jhk_ad_1 , so i dont want that , i only want keys starting from ad_1 , hope u got what i am trying to say.
i mean i want all the keys that are starting from the runtime value i am getting -
Hello,
how can i execute java code on clientside?I guess you will have to add an applet to the web page.
http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/applet.html -
Convert strings to executable java code
Hey,
I'm not sure how easy or hard this is to accomplish, but I am looking for a way to take a string from a JTextField and use it as a control structure for an IF block.
For example, the user inputs 'keyword=="test" || keyword=="test2"' I want to use it in an if block to control it.
Is there a way to do this? I realize the java file is already compiled in a class, so the string would probably be incapable of doing such a thing.
Any thoughts would be appreciated!Basically this is impossible, because Java is a compiled language, but there are ways around it.
Actually the ways are all basically one way: use an interpreted language. You can embed one into Java. You can write your own, new language (it could be a small simple mini-language, for example one that only evaluates boolean expressions; this is easier than it sounds), or you can use one that already exists.
There already is an interpreted language for Java. It's called BeanShell. Also I'm told that someone has written a javascript interpreter for Java, but I don't know the details.
I'd suggest Googling for BeanShell. It sounds like the quickest, easiest solution.
But be careful: letting users execute arbitrary code can be a huge security hole. -
How to read from a .properties file...?
Hello all,
I'm new to this forum.
I have a problem in reading data from .properties file...
Follow is my properties file...
log4j.properties
log4j.rootLogger=warn, file, mail
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=D:\log.txt
log4j.appender.file.threshold=info
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
#email appender
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#defines how othen emails are send
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost="smtp.Honeywell.com"
log4j.appender.mail.From=[email protected]
log4j.appender.mail.To=[email protected]
log4j.appender.mail.Subject=Log ...
log4j.appender.mail.threshold=error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
I want to access file path given in .properties file..
I'm coding like this...
Properties props = new Properties();
String p=props.getProperty("file.FILE");
The above code is not getting me the string.. it shows null value...
Any solution...?
Thanks in advance......RahulSharna wrote:
public Properties getProperties(String fileName)throws Exception{
Properties prop = null;
FileInputStream fis = null;
Exception e = null;
File file = new File(fileName);
if(!file.exists())
new FileNotFoundException(fileName);
try{
prop = new Properties();
fis = new FileInputStream(file);
prop.load(fis);
}catch(Exception exp){
e = exp;
}finally{
if(fis != null){try{fis.close();}catch(Exception ep){}}
fis = null;
file = null;
if(e != null)
throw e;
return prop;
}Hope the above snippet helps :)
REGARDS,
RaHuLYou do know that you can throw out of the catch block without "short-circuiting" the finally block, right? Making the declaration of e completely foolish. (Unless you actually want to do something after the try/catch block, of course.) And, if all you're going to do is throw the exception anyway, why bother catching it? -
Java.lang.NoClassDefFoundError when executing JAVA code
Hy everyone,
Trying to execute some java code through forms I got this error when running my program : java.lang.NoClassDefFoundError : simple (where simple is a java class I developped).
These are the steps I followed:
1- Devopping a simple JAVA class (simple.java) and compiling in JDK 1.4 (for compatibilty with forms 10.1.2.0.2)
2- Creating the JAR file
3- Copying the JAR file in <ORACLE_HOME>\forms\java
4- Adding the adress of the JAR file in CLASSPATH (environment variable of the server)
5- Adding the adress of the JAR file in CLASSPATH (environmental file of OAS default.env)
6- Importing the JAVA class trought forms builder (program>>import java class)
7- Invoking the JAVA class via the PL/SQL packages created by forms builder
8- Running the program
Thanks for your help.
Regards.In most cases, you should not have to stop and restart OC4J_BI_FORMS to pick such changes. However, since you are having problems, I would ensure that all frmweb processes have been stopped, then stop and restart OC4J_BI_FORMS and retest. If that doesn't work, you should review how you imported the java into your app. Look closely at the Importer options you used and ensure that you have not change the file name at any point. Because you are working with Java, case sensitivity is critical.
Also, where are you seeing the error message? Client java console or in a server side log? If server side, exactly which log file is reporting the problem? I would suggest you post the first 4 ro 5 lines of the error and not just the NoClassDefFound part. -
Executing Java Code in ODI Procedure
Hi All,
I have following java code which i need to write on ODI procedure but i am not sure which technology to chose (Jython,Sunopsis API or Java BeanShell).
I tried to execute the procedure Jyhton with <% "Java code"%> but getting the error.Any boddy can suggest where i doing wrong.
<%
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
import java.util.Hashtable;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
String userName = "HXXXXXX";
String CN1=null;
String Dis_Name=null;
String Mem_of=null;
String Mail=null;
String SGID=null;
File file = new File("C:/Project/ODI/LDAPID.txt");
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "LDAP://XX.if.YYYY.net:389/OU=XYZ,DC=ZZ,DC=if,DC=XYZ,DC=COM");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, new String("" + "\\" + userName));
env.put(Context.SECURITY_CREDENTIALS, "");
DirContext ctx = null;
NamingEnumeration results = null;
ctx = new InitialDirContext(env);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = ctx.search("", "(objectclass=person)", controls);
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
while (results.hasMore())
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
Attribute attr = attributes.get("cn");
String cn = (String) attr.get();
CN1=(String.valueOf(attributes.get("cn")));
Dis_Name=(String.valueOf(attributes.get("displayName")));
SGID=(String.valueOf(attributes.get("userPrincipalName")));
Mem_of=(String.valueOf(attributes.get("memberOf")));
Mail=(String.valueOf(attributes.get("mail")));
bw.write(CN1 + " || " + Dis_Name + " || " + SGID + " || " + Mail);
bw.newLine();
bw.close();
results.close();
ctx.close();
%>
I am getting following error.
The application script threw an exception: java.lang.NullPointerException BSF info: CODE_JAVA at line: 0 column: columnNo
Please suggest what went wrong with the code.
Thanks
RegardsIn Jython you don not need to declare the type so String userName = "HXXXXXX"; should simply read userName = "HXXXXXX" . Lots of your code need to be rewritten to work with Jython if you choose that as your technology.
-
Execute java code before rendering the page
Hi,
In a task flow, can I execute some java code before the page/view is rendered (i.e. some preprocessing). I would need to be able to have access to the bindings on the page.
Thanks!Can you try doing as specified below:
If it is simple JSPX, you could use the phase listener as follows:
JSPX Code:
<f:view beforePhase="#{SamplePageBean.phaseListener}">
<af:document id="d1">
<af:form id="f1">
<af:panelFormLayout id="pfl1">
<f:facet name="footer"/>
</af:panelFormLayout>
</af:form>
</af:document>
</f:view>
Bean Code:
public class SamplePageBean {
public SamplePageBean() {
public void phaseListener(PhaseEvent phaseEvent) {
if (phaseEvent.getPhaseId().equals(phaseEvent.getPhaseId().RENDER_RESPONSE)) {
// DO NECESSARY INITIALIZATION
Thanks,
Navaneeth -
Using a button of type=button to execute java code
Hello,
I here what I need to do.
- A user fill a form
- He press submit
- the button goes and execute some java code and then refresh the page (same page)
Now I don't want to use a input=Submit, that call a a servlet that just update the information, and output to the servlet;
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<meta content=\"1; url=" + "SamePage.jsp" + "\" http-equiv=refresh>");
out.println("</head>");
out.println("</body>");
out.println("</html>");Instead, I would like to do: <INPUT TYPE="button" VALUE="Close Window" onClick="window.close();"> but instead of JavaScript in the onClick it would be JavaCode that would update the object (already instantiated in the JSP) and would then refresh the page.
Is this possible?
thanks.Hi,
it is not possible because JSP code is executed server-side, while javascript code is executed client-side (in client's browser). -
Class compiling/executing JAVA-Code??
Hi!
Stupid question: ;-)
Is there a possibility to "parse" Java-Code into a JAVA-Class or to give JAVA-Code to a class that compiles the code and execute it?
Thanks for answering!
Mark Hauchwitz.background: we're running servlets and simply need to "parse" specialized/customized java-code for every customer into the servlet code. Source: database or whatever...
How to get started?
Maybe you are looking for
-
Mavericks 10.9.5 VPN Cisco IPSec stopped working. Please help.
My machine with (what might be) relevant software: Macbook Pro mid 2012 Mavericks 10.9.5 Server 3.2.1 Xcode 6.0.1 I use VPN to connect to Cisco IPSec. This used to work fine. Two days ago I noticed it stopped working. Over the few days before I insta
-
I do not have any images in the library section of Aperature. All of my images are in the projects but not the library. Not the ratings, Not the date sections etc. This may be tied to the same issue I am having with the Dance project and no images th
-
I would like to turn a long alphabetized list of items into 3, side-by-side, equal length columns (ala newspaper columns). I can do this easily in MS Word by selecting the list and clicking a button for 3 columns of text. Is there a way to do this in
-
Level Control with PID Control & Pulse-Width Modulation
Hi all, I have attached my program which I'm having trouble wiring up in the block diagram.... I'm fairly new to labview, but basically I have a level control project with an analog input cistern arm turning a pot for my test tank (configured a
-
We have two DB instances running on similar platforms and both the DB's are on the same patch set level. We are trying to centralize all the bypass the cron scheduler and make use of the DBMS_SCHEDULER thus centralizing from the DB itself. At this en