Relative Paths in VS Code - visual-studio-code

I work with a multi-root workspace in VS Code. Here's my folder structure:
project-one
-node_modules
-public
--css
---styles.css
--img
---global
-----logo.svg
--js
---main.js
--index.html
project-two
project-three
When I reference files in my index.html file, VS Code always wants me to write it like this (in index.html):
src="img/global/logo.svg"
That doesn't really make sense to me. Logically, I would write the relative path to the logo with a leading / before img as the img folder is at the same level as index.html. However, that doesn't work.
Can anybody explain me why? And will the path declarations work correctly like this when I upload these files to the server (the content of the public folder will then be at the root)?
Thanks.

Related

Difficulty using BufferedImage in Eclipse

I have stored an image in a Resource folder 'Images':
src
-com.program
-Images
In the program I use
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage.png"));
to import the image.
This works fine. However, if i change the name of the image at the source(say to myImage1.png)
and try to execute
BufferedImage image =ImageIO.read(getClass().getResourceAsStream("/myImage1.png"));
I get Input==Null.
I've been try to get this to work for a while and tried various suggestions on other threads.
Any ideas?
Thanks!
The problem was most likely:
The image was in your src folder inside your project, but when the program runs, it runs from another folder containing your compiled classes. This folder did not contain the png, so you get the input == null exception (getClass().getResourceAsStream(...) returns null when resources cannot be resolved).
To make it work, you need to mark the images folder a resource folder (using Eclipse, Maven or favorite build tool), and make sure that the contents of that folder is on your class path when the program is run.

How to resolve Unable to find file.cpp in path(s) in Marmalade?

I'm just trying to begin develop a game in Marmalade (6.3). But when I have made my new sources (.cpp, and .h) and added them to the mkb, and then trying to run my program, then I got an error which says that Unable to find file.cpp in path(s). It's for all of my files except the files (game.h, game.cpp, main.cpp) which were made by Marmalade when I have chosen the new 2D game project. Should I add my .cpp and .h files to anywhere else?
Thanks
It is difficult to give a categorical answer without more info. However my guess is that you've copied and pasted from an example and not understood about the syntax of the files section. Basically:
files
{
(foo)
humbug.cpp
)
The "(foo)" might look very innocent, but it actually says that humbug.cpp is actually in directory foo - relative to the mkb file. It is common practice to actually use "(source)" and put all the source files in a directory of that name - making the source layout a bit neater.
Naturally if you have (source) and don't put the files actually in directory source, they won't be found. My guess is that is what you are seeing.
Just to clarify previous answer, The format of files directive is like this -
files
{
(<Path relative to MKB>,<Alternate Path>)
["Name of the parent Group in VS/XCode project","Name of the subparent group"]
fileName.cpp
fileName.h
}
for example I have two files SoundManager.h and SoundManager.cpp in System folder of Source, while MainMenu.h and MainMenu.cpp in Source/UI. Now the files directive would be -
files
{
(Source/System)
["Source","System"] #This part is not required, it's just to arrange your files in IDE project
SoundManager.h
SoundManager.cpp
(Source/UI)
("Source","UI")
MainMenu.h
ManinMenu.cpp
}

javascript file directory redirect?

I have some javascript that changes the title image based on whatever the host is. My problem is that the redirect path I have "../images/file.jpg" does not work for all the pages that I have. Some of my main pages are in the main folder directory, the others are in a separate folder within the main directory folder called page. All the images used(not located) in page treat page as the main dir.
Does anyone know a way around this, without me having to move the images?
this is my script:
if(host == 'mysite.com') {
document.getElementById("geekhospitalextended").src='../images
/logo/IPD/title/IPD extended.png';
document.getElementById("urlTitle").src='../images/logo/IPD/title/
IPD extended.png';
}
I have thought about adding some code like:
if(pathname == 'mysite.com/directory1/directory2/images') {
document.getElementById("geekhospitalextended").src='../../../images
/logo/IPD/title/IPD extended.png';
document.getElementById("urlTitle").src='../../../images/logo/IPD/title/
IPD extended.png';
}
What could I do if I wanted to set the src path given that certian keywords are included in the path name
Any ideas?

The file InfoPlist.strings couldn't be opened

Can anyone please help me? What should i do to fix the error "The file InfoPlist.strings couldn't be opened because there's no such file"? It's appeared after i've updated my project from SVN. Actually THERE IS InfoPlist.strings in my project, i have no idea why Xcode doesn't see it.
Maybe the following information will help you to understand what's going on: when i expand InfoPlist.strings by clicking on the triangle next to it, then it shows: InfoPlist.strings (English), InfoPlist.strings(German), InfoPlist.strings(French). The English is black, but French and German are red, so i suppose it is probable something wrong with them and it might be the cause of the error. Also, i've got Localizable.strings, which behaves in similar way. It has (when expanded) Localizable.strings (English), Localizable.strings(German), Localizable.strings(French) and just as in InfoPlist.strings English is black whereas French and German are red.
When i look inside my project's folder - there is the following there: a folder named en.lproj contains Localizable.strings and InfoPlist.strings. Folders named fr.lproj and de.lproj contains the same - Localizable.strings and InfoPlist.strings. Seems like i've described everything. Please explain me what to do. I work with Xcode 4.2
I have just managed to fix this problem !
My second Strings.plist file (FR) had an absolute path. The drop down menu for path type (absolute, relative) was greyed out in the info pane of xcode so I could not change it to a relative path.
The solution is to change it manually in the project.pbxproj file:
If you open the file to view the source, and search for "plist", find the following line:
/* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = /Users/[YOUR-USER]/[PATH_TO_PROJECT]/fr.lproj/InfoPlist.strings; sourceTree = "<absolute>"; };
Notice that the path attribute is the full path to the file, and that the sourceTree attribute is set to <absolute>.
Now change the path so that it's relative:
/Users/[YOUR-USER]/[PATH_TO_PROJECT]/fr.lproj/InfoPlist.strings
should become
fr.lproj/InfoPlist.strings
Also change the sourceTree value from <absolute> to <group>
The line should now look like this:
/* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Repeat these steps for all your localizations that are stuck with absolute paths.
Save the file, commit the changes, and voilà! no more no such file problem :)
info.plist source code:
like:
....
{isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; };
....
check "path" is a absolute path?
Had the same problem, easy fix for me: select the plist file in xcode and make sure its "Target Membership" is ON (for the build you are doing).
The path to your Info.plist file is defined in the build settings for the target. Look and see what it's set to. If the project has come from a different machine, it might be an absolute path, but it really should be a path relative to the project root, like Sources/Info.plist.
Best information is right here. Sorry to be so cheesy as to put a link to this - but they edited it in September - and now it makes sense...
http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
I just recreated the files (with empty content) it asked for in the paths it asked for them, since I am new to XCode and it didn't seem to affect my current project I decided that was a acceptable solution/shortcut to proceed.
The solution for this particular instance of the error was “Info.plist couldn't be opened because there is no such file” was that I had deleted all of the files in the "Project Tests" folder, but was still had "Project Tests" listed under my targets. After deleting the "tests" target, the project built successfully.
I got this error when i pulled my cohort's changes to my local so that i can review and test them. I checked all settings suggested in this thread but they all looked correct-ish. My fix was just to blow away the branch, reset to master and pull the updates to a clean branch. The ol' reboot everything technique.

Eclipse PDE: given a relative path like /ProjectName/lib/something.jar, how do you get a full filesystem path?

I'm trying to find a path to a jar file that's in the raw classpath. getRawClasspath returns a collection of IClasspathEntry objects. I can call getPath on those.
But getPath returns something weird: an IPath that starts with the project name, like:
/ProjectName/lib/something.jar
What's the right way to turn this relative path into a full-qualified OS path? At first I thought I could just add the path to the workspace root, but that doesn't work since there are often intermediate directories between the workspace and the project.
And more generally, how do I know what to do with an IPath returned by a method? It seems like I never know what that IPath is; relative to the project, relative to the workspace, relative to the project but with the project name as the first element, relative to the phase of the moon... It's all baffling, and the documentation is never helpful - or at least I don't know where to look.
UPDATE
I'm even more confused now. The problem still is that, when you have an IClasspathEntry, it's still unclear to me how to resolve it to a filesystem path.
The answer that says "if a path starts with a / it's an absolute path (relative to the workspace) isn't correct. The problem is that the getPath method on an IClasspath returns one of two things: a path starting with a slash that's relative to the workspace, or an IPath starting with a / that's an actual filesystem path. Yes, two completely different things are shoved into one type. You get the filesystem variant when the jar is outside the workspace, and you get the "absolute" variant when it's in the workspace.
I think part of the answer is that an IPath, by itself, is only a fancy string. You have to know where it came from to make sense out of it. It doesn't carry the right sorts of information to be useful on its own.
So what's the right way to deal with this?
try this:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember("/ProjectName/lib/something.jar");
System.out.println(res.getLocation().toString());
Paths in Eclipse are complicated, and there are a few other situations that you haven't mentioned, like classpath containers (JRE is an example), linked resources outside of the workspace and classpath variables.
To simplify, I suggest you use getResolvedClasspath instead, that returns only 'simple' classpath entires (no variables, no containers). According to its Javadoc, it returns absolute paths, and their interpretation depends on the kind of the entry:
CPE_LIBRARY - if it's an external library, it's a filesystem path (and it has no associated resource, meaning you can't find it with findMember). Otherwise, it's a path based on the workspace root
CPE_PROJECT - absolute path to the project
CPE_SOURCE - absolute path to the source folder
All absolute path are interpreted in the workspace. If you need the file-system path, you need to go through getLocation.
As a side-note, there is no 1-to-1 mapping between file-system entities and workspace resources. Because of workspace links, you may have several workspace paths pointing to the same (file-system) location.
This is the best I could come up with, and it totally is an ugly hack, yes:
private IPath getCorrectAbsolutePath(IJavaProject project, IPath path) throws IllegalArgumentException {
final String projectName = project.getProject().getName();
if (path.segmentCount() > 1 && path.segment(0).equals(projectName)) {
IPath projectAbsolutePath = project.getProject().getLocation();
IPath relativePath = path.removeFirstSegments(1);
return projectAbsolutePath.append(relativePath);
} else {
if (!path.isAbsolute())
path = path.makeAbsolute();
if (!path.isAbsolute())
throw new IllegalArgument("Cannot make IPath absolute: " + path.toString());
return path;
}
}
I have a suggestion, look picture attachment, find "location" property from properties of any plugin of eclipse , maybe can find it where is from. but sorry I have no 10 reputation, you can see picture from picture url