Create Assemblies with Additional Files To Store data files in a relative path to the referenced assembly - u-sql

According to U-SQL reference about CREATE ASSEMBLY statement:
https://msdn.microsoft.com/en-us/library/azure/mt763293.aspx
When we include additional files with the assembly from the store, we can definitely define a relative path for each file in the store we are referring to, however, what if we want to locate it in a relative path that other dlls are expecting while executing.
Example :
CREATE ASSEMBLY BusinessLogic FROM #"/Path1/BusinessLogic.dll"
WITH ADDITIONAL_FILES =
(
#"/Path1/Path2/dataFile.xml",
)
Now while BusinessLogic.dll is running, it's expecting dataFile.xml to be in relative directory /Path2, which is not preserved in the runtime (knew that from local debugging), and thus the whole execution fails, how to preserve this relative path for additional files ?

As the documentation you refer to explains, the additional files are being placed into the working directory at the location without a directory right now:
This clause optionally specifies the name that is used for the additional file, when it is placed into the runtime working directory. The string literal has to be a valid filename (and not contain a path) or an error is raised. Note that this should the name of the file that the main assembly will be using to refer to the file or the assembly code will fail to find the file at runtime and raise an error.
So folder structures are currently not preserved. What can you do?
Please file a feature request to support relative path names in the additional file AS clause.
You can deploy the files inside a ZIP file and then unzip them inside your custom assembly to get them to the right place.

Related

Meteor "use strict" with global alias

In another SO post here, the second option is to write G.this; in the first "top" file in order to create a namespace.
And then write "use strict" on the top of every other js file.
Is that all the content of such a file? and if so, where the "top" file should be located (server, client, both) and what name? as Meteor loads files based on their paths. Thanks
One of ways to create a global namespace in Meteor (as suggested in the SO answer) is to have a file where a global alias to this is declared, such as:
G = this;
This file should, ideally, be loaded first and on both client and server.
To achieve this, according to the doc:
Files within lib/ directory are loaded first (after loading template files on client).
Meteor will load any file outside client/ or server/ directories on both client and server.
Where no other rules may apply, alphabetical ordering of the paths is used to determine load order of the files.
So, in keeping with these rules I would save the file as app.js (or any similar name that would come first alphabetically). Then I would place this file at the root of lib/ folder so that it gets loaded both on client and server.
So, the path to app.js would be : ./your_meteor_project_root/lib/app.js

Creating a new file without using a ServletContext

Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.

How to get exact path of servlet where it is running?

I have an application that I use in a servlet. The application assumes the text database residing in the same directory where it is being executed. When I am trying to use it in servlet and even after placing the text database files in /WebContent, /DataProject and also src folders. The application cannot find the database. I need to know exactly where the servlet file is being executed so I can place the database files in the same directory. I have already /.metadata/.plugin......../tmp0/wtpwebapps directory. Any help will be greatly appreciated.
Usually when we access files in java we give the absolute path. Dont use the relative path. We use relative paths for jsp/html/css etc. For accessing normal files use the complete path. So put the files in /home/tomcat/.../../directoryDatabase

get path to an included file on Classic ASP?

I have a file that is being included, in that file there's
Server.MapPath('../_data") which doesn't work
since that file included is not in the same Server.MapPath as the file executed.
any Idea of how I can get the included file's path?
To clarify the situation, I added a picture
As you can see, I'm including a file from one site to the other
(no other choice there), so that the server.mappath is intended to be different, though
the result is that on the included file I get the mappath of the executed file.
You should better use relative paths.
Relative paths start with / which means start from the root of the site..

getContextPath using servlet

Context path in jboss-web.xml is mentioned as /Test, but my war file name is Test-0.0.1.
I need this war file name using HttpServlet. Please tell me the function name.
i tried getContextPath(), but it returns Test.
Thanks
Here is the list of functions that are available, along with a graphic showing how they are related. in this example, the war file name is usually in the "context path" piece, in this case "myapp". This is a folder create by TomCat from the WAR file, and while based on the WAR file name, it does not need to be the same. Look for a folder with a name like "Test".
(From HttpServletRequest Path Decoding)
If the WAR is expanded, you could use ServletContext.getRealPath() in combination with File.getName() to obtain the expanded folder name. This will be the same as the WAR file name.
String name = new File(getServletContext().getRealPath("/")).getName();
ServletContext.getContextPath() is the way to get the context path. It can differ from the war-file name, but I can't think of a reason you may need the war file name.
From the Servlet API there is no way to access the war file name. The war file name is different from the context root. And , even the ServletContext.getRealPath() is the extract location of the war file, which can be different.

Resources