Giving relative path to java applet param - applet

How can i tell this java applet to take the .jar file from the same folder where the .html file is?
I have tried every possible way i know, and only "http://localhost/blabla/some.jar" or "file:///c:/blabla/some.jar" works in that case, so i need to type the absolute path every time.
Is it possible to make it working with the relative path ?
<param name="archive" value="some.jar">
Because that doesnt work, the java applet gives an error "file not found" even when the file is in the same folder...

Specify the codebase attribute in the tag as the folder "blabla"

Related

creating Executable Jar with input file on eclipse

I am trying to create an runnable Jar on eclipse.
After creation, Eclipse give me error message saying that its was created with compiler error.
When I ran it on the command line, it throw IOException, saying that I cannot find the input file.
I have file path within the project to read number of .jpg files.
I think these are not included for some reason when it creates the Jar file.
Can anyone help me with this?
Here is how I'm Accessing the files in my code
ImageIcon icon = new ImageIcon("src/images/" + (i + 1) + ".jpg");
file = new File("src/images/" + (i + 1) + ".jpg");
read = new Scanner(new File("intensity.txt"));
It depends on whether the images shall be packaged into the final jar file or loaded from some directory. The former will not rely on absolute paths as the latter one might, while the latter one allows easier adding of images or exchanging them -- but that really depends on what you need. (There may be many other caveats/advantages/disadvantages... you name it. Searching on stackoverflow with the right keywords may help you out, but read on)
Running a project from within eclipse sets up several things like classpath and the working directory is usually set to the project's base path. Hence, the executable may "incidentially" find the images. It may not always be that obvious what eclipse does. I suggest you have a look at and make yourself familiar with the "run configurations".
If you want to include the files into the jar-file, you may also have to adapt the project's Java Build Path >> Order and Export settings to include the image directory.
You may also want to have a look at the following Q/A: Load image from jar and outside it in eclipse

Reference txt file from code in Intellij

I have a very simple example in Scala for reading a text file. The example is made in IntelliJ. However when I try to use io.Source.fromFile("..\..\resources\example.txt"), I get a FileNotFoundException. The code works when I type in the absolute path.
Can anyone tell me how to use relative paths for specifying a file in Intellij project?
the directory structure:
Paths are relative to the current/working directory, i.e. the directory from which the java command is executed.
When an application is executed from IntelliJ, this working directory is configured in the Run configuration used to launch the application.
So, go to Run - Edit configurations..., then find your run configuration, edit it, and see what the field "Working directory" contains. By default, the working directory is the root directory of the project.
Note that, unless the String escaping rules are different in Scala from Java, the path must be separated by slashes:
"../../resources/example.txt"
, or the backslashes must be escaped:
"..\\..\\resources\\example.txt"
Also not that if your goal is to bundle the text file inside the jar of your application, you shouldn't use file IO to read it, but use the ClassLoader.getResourceAsStream() method.

How exlude properties when building executable jar in Eclipse?

This question has been covered here before, but the only solutions I could find were in relation to a project using Ant or Maven. I am using neither. Here is the situation:
I have some application parameters in a properties file. This file is located in my Eclipse project (but in the src folder) and used when I run the application from Eclipse. In addition, I would like the application to also run as an executable jar file, in which case the user can provide the name of a properties file to use in a command line parameters.
The problem now is that the properties file from the project is always packaged into the executable jar and therefore the user is not able to easily modify the properties (yes, I know that (s)he could unzip the jar, but I want to avoid the extra steps).
How can I prevent the properties from being packages into the executable jar file?
Cheers,
Martin
Create a executable jar without properties file in it. Place both jar and properties file in a folder. Now add little code in your main program which should look for a properties file in the same folder and get the complete path of it. And then you can do something like this
System.getProperties().load(new FileInputStream(completepath));
So now your properties will be loaded into system properties with out affecting the actual system properties. You can access your properties by System.getProperty("Propertyname");
Hope this helps. Let me know if you have more questions.

XML parsing in scala

I am parsing XML file in scala using
val data = XML.loadFile("changes.xml")
I have the changes.xml under the src folder. When I run this the code throws a FileNotFoundException. Any idea how to solve it or any insight on how scala looks for the
files in the classpath would be helpful.
See what the current directory is using
new java.io.File(".").getCanonicalPath()
Since you're opening the file with a relative path, it looks for the file in the process's working directory.
Since you're placing your file in the source tree, I assume you want to ship it with the application jar.
Then tell your IDE to copy the file to the ouput folder (maybe this is already happening) so it lies in the classpath. If you place your file in the same folder as the class from which you want to load you can simply do the following. Use in Java/Scala
Class.getResourceAsStream("changes.xml")
Link to API doc.
Edit
You can use XML.load("changes.xml") and I think it will load the file in the same way as Class.getRessourceAsStream. So try putting your xml file into the same folder as the class and make sure the build process copies it into your binary output folder.

Relative paths in web.xml with Eclipse and appengine

I want to reference a local file for web-app_2_3.dtd in my web.xml file, but can't find a way to use a relative path. Since this file is used on multiple machines the relative path is important.
I put the dtd file I want to use in the WEB-INF directory (with web.xml) and have tried to reference it with things like "web-app_2_3.dtd" and "war/WEB-INF/web-app_2_3.dtd" and every permutation and depth of things like that I can think of.
Is there a variable I can use to reference the war directory, or something?
I have found that in the web.xml paths are relative to the webroot, so if its in the WEB-INF, the relative path would be something like /WEB-INF/web-app_2_3.dtd with no need for the war/ in front of it