Applets :: Having Access To Local Resources
Jan 31, 2014how I can configure an applet to get access to local resources such as file system, browser, etc.
View Replieshow I can configure an applet to get access to local resources such as file system, browser, etc.
View RepliesI am quite new to developing Applets in java. I recently made an applet that will play a particular sound whenever a button is pressed. The sound files are placed in the same directory as the applet class file and i access them by using
AudioClip clip=getAudioClip(getCodeBase(),"A.wav").
The Applet runs fine in the appletviewer but whenever I try to open it using any browser like Chrome,IE,Firefox the applet loads but sound isn't played. I checked the java console and it showed
"java.security.AccessControlException: access denied ".
My questions are:
1. How do I allow the applet to get access to those files?
2. When the Applet is running from the local file system why CAN NOT I access those resources via getCodeBase() ???
3. I googled and found that I can sign a JAR and that can have full access to the computer. But how do I create a JAR from an applet (which has no Main method) while it asks me to point to the main class in the manifest?
I'm working on an application and I would like to package my resources (icons, about dialog images, splash screen images, release version text, etc.) in the jar file I'm going to distribute for deployment. I would like to access these resources from the JAR file in my deployed code. But I would also like them accessible when I'm running the code in my Eclipse IDE. Is there a way to do this using only one code base?
My Eclipse project structure is src (folder) which contains my source code, bin (folder) which contains my class files and res (folder) which contains my resource files.
I am using the javapackager utility to create my deployment JAR and build a self-contained deployment .exe for deploying to Windows.
Is there a way to have the javapackager build a single JAR file from multiple sources (i.e. my bin and res folders)? What do I have to do in my code so that the same code can be used to load resources when I'm running in Eclipse and the self-contained deployment?
In my java app there is a code which reads the properties file from src/main/resources folder.
Java Code:
@Component("mailerProperties")
public class MailerProperties {
private static Properties properties;
public MailerProperties() {
properties = new Properties();
[Code] ....
Now I need to create a jar file and also remove the properties file from src/main/resources folder and place it outside the jar file(in the same location as jar file) so that data inside it can be changed easily in future.
Question: Currently it uses ClassPathResource("mailer.properties") to read the prop file. What change I need to make to read it from outside the jar file...
I have one Project -"A".Inside of that I use, .XLS to read data.
Structure - A/src/TestData
Inside of the TesetData - I have placed XLS files.
I have main method in TestDriver class.If I run this in Eclipse, running fine.But after exported to executable/runnable Jar, and ran via command line (command - jar -jar myjar.jar), I see issue: "Exception in thread "main" java.io.FileNotFoundException: srcTestDataTestCaseController.xls"
public static void main(String[] args)
throws Exception
{
ResultSet rs;
rs = readExcelData(testControllerName, sheetName, "");
}
As I use main() method which is static, I am getting error if I write like the below:
public void getXls(){
String testControllerName ="TestCaseController.xls"
TestDriver.getClass().getClassLoader().getResource (testControllerName);
}
How to read/access the XLS, after I exported as runnable jar
i want to list files from resources folder like this:
@ManagedBean
public class galley implements Serializable {
private List<String> list;
@PostConstruct
public void init() {
list = new ArrayList<String>();
[Code] ....
but it give me a null pointer exception on fList .... The directory of resources is :
How is this caused and how can I solve it?
I am new to applets, and my manifest file is:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Permissions: all-permissions
Created-By: 1.6.0-internal (Sun Microsystems Inc.)
Name: com/myPackage/test/client/TaskApplet.class
SHA1-Digest: pLmraui35IkgfAq+v3WGj1LwCYQ=
The error I get is as follows...When the page is loaded I get the following error: java.lang.SecurityException: class "com.myPackage. test.client. TaskApplet" does not match trust level of other classes in the same package
I am reading input from a file that has following information:
line 1 = numbers of integers in array,
line 2 = elements in array1,
line 3 = elements in array2.
These lines constitute a test case. There are 1000 test cases in the input file.
So basically, I read the length of arrays, populate the arrays by reading from the file.
The code is below ( I have not included reading input code):
while(test_case<1000){
if (count == 1){ //count keeps track of lines in input file
vec_length = Integer.parseInt (tokenizer.nextToken());
count++;
continue;
}
if (count == 2){ //populates array1
vector1 = new int[vec_length];
for (int i = 0; i < vector1.length; i++)
vector1[i] = Integer.parseInt (tokenizer.nextToken());
count++;
continue;
}
Array2 is populated using the same as above code. However when I use the following code:
for (int i=0; i<vec_length; i++)
temp += vector1[i]*vector2[i];
I get " local variable vector1 and vector2 have not been initialized error". But both arrays have been initialized in the if{} block. Is it because initialization was local to if block?
As a studyproject I'm currently writing a class the allows me to get al fun dates (like when eastern is in a given year, what day a given date has, calculate the date of tomorrow).
While working on the following method:
public String getNextDate (int day, int month, int year) {
String nextDate;
int nextDay = getNextDay(day, month, year);
int nextMonth = getNextMonth (day, month, year);
int nextYear = getNextYear (day, month, year);
return nextDate = "the day after " + month +"-" + day + "-" + year + " is " +
nextMonth + "-" + nextDay + "-" + nextYear + ".";
}
I get a notion in my lovely IDE (eclipse) reminding me I'm not using nextDate ("The value of the local variable nextDate is not used"). But I feel I really do use nextDay here. So either I'm making a coding(style) mistake giving me this notion or I should just ignore this notion.
you can also refer this link Local variables in java?Local variables in java?To meet temporary requirements of the programmers some times..we have to create variables inside method or bock or constructor such type of variables are called as Local Variables.
----> Local variables also known as stack variables or automatic variables or temporary variables
----> Local variables will be stored inside Stack.
-----> The local variables will be created while executing the block
in which we declared it and destroyed once the block completed. Hence the scope of local variables is exactly same as the block in which we declared it.
package com.javatask.in;
class A{
public static void main(String args[]){
int i=0; // Local variable
[code]....
Here, I have just tried out to take a value from the database and storing it into local variable then I want to have that value in the value attribute of <input> tag but somehow, I can't get it..
Here, below is my code..
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL]....">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
[Code]...
is it necessary that inner classes inside a static method be static . If yes Why?
View Replies View RelatedI edited some lines from "[URL] ...." and saved it as html file; now if a friend want to do a search in Wikipedia for cats, the edited page should show up instead of original page.Is there a way to do this using java script.
View Replies View RelatedBelow is my ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<display-name>TestEJB</display-name>
<enterprise-beans>
<session>
<ejb-name>TestSessionLocal</ejb-name>
[code]....
All my classes implement proper local classes EJBLocalHome and EJBLocalObject.This configuration used to work fine in JBOSS 5.1.0 G
Let's say I have a loop that loops through objects in an ArrayList then does stuff with them. Is it better for me to store the object in a temporary local variable and do stuff with it, or always use the ".get(arrayindex)" thing?
View Replies View Relatedpublic class Apples{
public static void main (String args[]){
int array[]={21,16,86,21,3};
int sum=0;
int average;
[Code] .....
Eclipse: Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The local variable average may not have been initialized
at Apples.main(Apples.java:11)
How to implement non local means filter in java?
View Replies View RelatedHow to check if a web page is synchronized on a local server in JSP ? I have tried to make database updation synchronized in jsp but how can i check it on local web server (tomcat) ? I have used Oracle database.
More Info:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe","username","password");
balance=balance-1500;
String query1= "update bank set bal=? where card_no='"+cnumber+"'";
PreparedStatement st1 = con.prepareStatement(query1);
st1.setString(1,String.valueOf(balance));
int qresult1 = st1.executeUpdate();
This is some of the code in which I have not applied any synchronization. In simple words, I want to know how to test if synchronization part is really working or not ?
My main motive is... I am trying to make an admission form and I want a limited number of seats but I want after every registration process my database updates the seat numbers accordingly and show the right information about how many seats are left to the user. (though in the given code i am just changing the balance)
Like in this example
<%!
PreparedStatement pst = con.prepareStatement("query");
%>
synchronization
<%
synchronized(pst) {
pst.setXXX(...);
pst.setXXX(...);
pst.executeXXX(...);
}
%>
Basically this code is supposed to create an int array of 50 elements, then pull the elements listed in positions 1-6 to make a lottery draw.
Problem is it gets down to that last "For" statement and then says "duplicate local variable i." If I attempt to separate it from the previous for loop with curly braces, then it gets mad and says it doesn't know what "local variable i" even IS. So I tried changing it to "j" in the last statement and it couldn't recognise that either. I feel like I need to change the variable name in that second for loop but I'm not sure how to make it understand that the second variable is going to be outputting the values from the first variable.
public class Lottery {
public static void main(String[] args) {
// TODO Auto-generated method stub
int []nums = new int [50];
for (int i = 1; i <50; i ++) {nums[i] = i;}
[Code] ....
I have a question regarding best practice in using local variables as my method return variable. I have a method like this:
myReturnObject getMyObject(String input) {
myReturnObject myObject = null;
try {
myObject = helperObject.someOtherMethod().getObject(input); //getObject has return type myReturnObject
} catch (Exception e) {
//log any problems
}
return myObject;
}
And I'm wondering if I rewrite like this if I'll see some performance optimization benefit:
myReturnObject getMyObject(String input) {
try {
return helperObject.someOtherMethod().getObject(input); //getObject has return type myReturnObject
} catch (Exception e) {
//log any problems
}
return null;
}
myObject can be quite large -- so I'm wondering if I can omit the myReturnObject local variable instance if it'll save some work from the garbage collector.
I would like to ask how i can create a bidirectional folder copy system with SFTP JSch is there any example. Like i see the code can only transfer file, I need to transfer a folder with many files from my pc to a server and the opposite.
View Replies View RelatedI am using findbugs and PMD as a code analyser. I am keep getting warnings to use local variables and method parameters as final.
I want to know if its a good practice to keep them final or what to do?
Sometime i have a private method which is 1 line longer. Sometime it is annoying to use final.
I have this code: [URL] .... It works on fiddle but on local it does not work. What should be the problem?
Fiddle:
$('#addnewline').on('click', function (e) {
e.preventDefault();
var $textarea = $('#thetext');
$textarea.val(function () {
return $(this).val().substring(0, this.selectionstart) + "<br>" + $(this).val().substring(this.selectionstart);
});
});
<button id="addnewline">New line</button>
<br />
<textarea rows="4" cols="50" id="thetext">Some text
I'm trying to create a server which sends the clients connected to it its local time. Looking at a few tutorials I've managed to connect the clients to the server, but can't send data to the clients. I've successfully done easier examples, without threading. I guess the problem might be im me not knowing what exceptions are for.
Client: When running the code "AAAAAAA" does execute but "BBBB" doesn't, so I guess the problem should be in fraseRecibida = entradaDesdeServidor.readLine();
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client {
public static void main(String[] args) throws Exception{
String fraseRecibida;
[code]....
I don't understand the exceptions, maybe I should give them a look before continuing with sockets. Being frank I'm not really sure why the while(true) is there.
import java.io.*;
import java.net.*;
import java.util.Calendar;
public class ServerThread extends Thread{
Socket socket;
ServerThread(Socket socket){
this.socket = socket;
[code].....
I've generated SOAP classes via wsimport from a local WSDL. All of the URLs in the WSDL point to the production services, but for testing I need to connect to a test location (different URL). There are dozens of examples on the web to set the endpoint, but it doesn't seem to be working for me - it's hitting the prod URL, not test.
PrepaidServices ps = new PrepaidServices();
ps.setHandlerResolver(new CustomHandlerResolver());
IPrepaidServices port = ps.getPrepaidServices();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, TEST_URL);
LOG.debug("New Port = " +
[Code]...
The debug correctly shows the TEST port being set correctly, but when executed, inside one of the handler resolvers, I have the following code:
private void logMessage(SOAPMessageContext smc) {
// These headers are null: WSDL_OPERATION PATH_INFO HTTP_REQUEST_METHOD HTTP_REQUEST_HEADERS
LOG.debug("WSDL_PORT = " + smc.get(MessageContext.WSDL_PORT));
LOG.debug("WSDL_SERVICE = " + smc.get(MessageContext.WSDL_SERVICE));
[Code]...
The top debug lines both show the PRODUCTION URL! Shouldn't at least the port be the DEMO URL that I'd previously set?
Am I doing something wrong?
I am developing one android chatting application. for that on Server side i am using WebSocket as war file.
It is working well on localhost the same tomcat. but when i try to connect on the hosting server, it showing http error..,