ClassLoader not recognizing programmatic jar file - jar

I have a program that creates java source code files, compiles them to create class files and “jars up” the classfiles into a jar using java.utils.jar. When the resulting jar is placed in a lib directory in another application, the classes are supposed to be recognized. Except the created classfiles are not being recognized. So I used WinZip to zip the same class files, renamed the “zip” a “jar”, placed the new jar in the lib directory and the files are recognized fine. Used WinZip to look at the first (programmatically-produced) jar and the WinZip-created jar and they look identical. Same paths, same original size, same compressed size. Also tried creating a zip via java.utils.zip and renaming it. Same problem. Does anyone know of any reason why the programmatic zip/jar files could not be recognized by the Java class loader?

Solved. Maybe this will help others. The argument to ZipEntry (and JarEntry) must use forward slash ("/") as the name separator in order for the ClassLoader to correctly recognize the included files. In particular, other separators, such as those returned by File.getAbsolutePath(), while seemingly happily accepted by java.utils.jar and WinZip, will not be recognized by the ClassLoader.

Related

What does $$[QT_HOST_DATA/get] do in a Qt Feature configuration (.prf) file?

Where is the following syntax used in a feature configuration (.prf) file? defined:
$$[QT_HOST_DATA/get]
I know $$[ ... ] is to access QMake properties as explained in the Qt doc, but where is the /get part of the notation in $$[QT_HOST_DATA/get] clarified? And what does it precisely do?
Also, inside a Qt .conf file, what is the difference between include (for other .conf files) and load() (for .prf files)?
If include(some.conf) merely consists in the contents of some.conf to be literally pasted into the including .conf file, what does load() do exactly?
I have found no info about the structure of .prf files.
https://doc.qt.io/qt-5/qmake-advanced-usage.html says that you can create .prf files, but says nothing about how these files are processed or should be structured?
Thanks for any clarifications you can provide!
where is the /get part of the notation in $$[QT_HOST_DATA/get] clarified? And what does it precisely do?
Nowhere, except qmake source code. It looks like all qmake properties may have upto four special "subproperies": xxx/dev xxx/src xxx/raw xxx/get. However, what are they used for is a mystery. Executing qmake -query QT_HOST_DATA/get produces (on my machine) just the same value as plain $$[QT_HOST_DATA].
I have found no info about the structure of .prf files.
Basically, .prf is just "system include file". There are two points, though:
All .prf files reside in a known location(s) pointed by QMAKEFEATURES variable.
BTW. QMAKEFEATURES is a sort of "protected variable". I managed to change it only with the help of (another undocumented) cache() function:
QMAKEFEATURES *= mydir # '*=' because of 3 passes under Windows
# 'transient' prevents creation file on disk
# only 'super' seems to work OK; no idea what's wrong with 'stash' or 'cache'
cache(QMAKEFEATURES, set transient super)
# now I can load .prf from <mydir> too...
Prf can be implicitly loaded by mentioning it in CONFIG variable. For example, CONFIG += qt (which is the default, btw.) results in include of <SomePrefix>/share/qt5/mkspecs/features/qt.prf Note that this takes place after the whole .pro was processed, so .prf file can be used to post-process user options.
what does load() do exactly?
It's just the version of include() designed specially for .prf. All it does, it simply includes .prf file. But, unlike CONFIG += xxx, it does this immediately, and, unlike plain include(), you shouldn't specify path and extension.

how deeply can the source path in windbg be nested?

If I have multiple binaries whose sources are scattered in various subfolders of an overlaying folder, would windbg have access to them if only the topmost folder was included in Source Path? As opposed to having to reference each project folder of each relevant binary separately.
Assuming, of course, that the sources are unique in the mentioned folder structure, i.e. there are no multiple versions of one and the same project, source, etc.
If you specify the parent folder for the source files in source path then it should traverse through the subdirectories to find the source files.
Note that it will perform a signature match against your source files, in the same way that Visual studio will complain that the source files are different to the loaded dlls.
The relative locations of the source files must match the original locations so if your source files are located in a different structure then you will need to do a manual load/browse to specify the location of the source files.
Can’t answer exactly, but I often have 3 top (parent) directories, and each have approximately 4-5 levels of sub directories. No problems. However nothing beats using a source server
Short answer: NO.
From windbg's help:
For each directory in the symbol path, the debugger looks in three
directories. For example, if the symbol path includes the c:\MyDir
directory, and the debugger is looking for symbol information for a
DLL, the debugger first looks in c:\MyDir\symbols\dll, then in
c:\MyDir\dll, and finally in c:\MyDir. The debugger then repeats this
process for each directory in the symbol path. Finally, the debugger
looks in the current directory and then in the current directory with
\dll appended to it. (The debugger appends dll, exe, or sys, depending
on which binaries it is debugging.)
You can move all projects' .pdb files to one folder or change projects properties and setup the linker to create the .pdb file in a specific folder so you have to reference only one.
I've been doing a bit of debugging on this myself. From what I can tell, the relative path of the file found from the SourcePath needs to match part of the end path of the path embedded in the PDB. For example:
I have a file on disk at:
C:\Users\User\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\windows\thread_local_key.rs
The path of the file embedded in the PDB is:
/rustc/c09a9529c51cde41c1101e56049d418edb07bf71\/library\std\src\sys\windows\thread_local_key.rs
✔ This SourcePath, and any below it, correctly finds the file:
C:\Users\User\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust
❌ This SourcePath, and any above it, does not find the file:
C:\Users\User\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src
Notice how with the failure case, the relative path to the file would begin with library\. The library path component is the first part of the path that is not found in the embedded path. I assume it does a path check for every relative address, recursively:
thread_local_key.rs
windows\thread_local_key.rs
sys\windows\thread_local_key.rs
src\sys\windows\thread_local_key.rs
std\src\sys\windows\thread_local_key.rs
library\std\src\sys\windows\thread_local_key.rs
etc.

jar file is not including in build.xml

What could be the reasons for a jar file not to include in build, even everything was given correctly. I tried the same syntax with other jar files which worked. But when i am using it for protocol buffers jar file, it is not being included.
Thanks !

Add application icon to air app while packaging with adt.jar: how to?

I built air app with icon in the past with flash builder, and everything was fine.
Now I have to build another app with adt(air developer tool), but I experience weird problems.
If I just place icon path relative to 'src' folder to app descriptor (as usual), it says:
error 303: Icon icon.png is missing from package.
If I use icon.png without path in app descriptor and then put this file everywhere(to root dir, to assets, to src, to build destination and so on), it again says error 303: Icon icon.png is missing from package.
If I try to add icon path to adt args like <arg value="icon.png"/> ( and put it to output folder as it seems that all path are relative to it in my case), it says The path icon.png is restricted. If you were trying to package Icon.png you should correct the case.
When I point to original file location ( <arg value="../src/assets/icon.png"/>), it outputs File ..\src\assets\icon.png is not relative to directory E:\projQ\flex\MyProject\bin (this bin directory is actually output directory). I've read unapproved comment on adobe forum that this is due to some sandbox limitations, but I'm not even sure that sandbox exists for adt( if it exists, then why? )
So, what shall I do to successfully add icon to that app?
I guess that using tools like resHacker to project's .exe will not help as .exe is just a launcher for .swf file, and anyway I consider that this awful way leads to the dark side of programming.
(P.S. can't add 'adt' tag that relates to adobe, not android.)
Nice. At last I've found the solution. So, the requirements for including icon while packaging manually with adt are:
Add file name to application descriptor without using any .. .
I beg you, don't even try to name your icon file icon.png. It is obvious name, and it was obvious for creators of adt. So it seems that they are renaming some files to icon.png or generating output to such file. Or put this file into some subdirectory of directory that is used as root by adt. Actually, error output exactly tells you to avoid using path icon.png. Correct the case phrase (which confused me) means rename your icon or move it deeper in directory hierarchy
Add path to your icon as command line argument to adt.
After generation you will see your icon inside generated output folder. You can remove it and application will still appear with your icon as expected.
This is more of an elaboration on the first point in the answer above to clarify for people like me who have been struggling with this issue.
The error reads "is not relative to directory", but what it means is "is not a child of directory". Basically even if you're trying to use a valid relative path, it expects it to point to something under your working directory. In my case the following trick worked:
./../..build/executable.swf
Replaced with
-C ./../.. build/executable.swf
-C makes ADT change directory to the one two levels above, and then you can specify the necessary file.
After playing with ADT a bit more, I now realise why it does that - the path you give to it will become the path within the package. So in the example above the file will be available inside the package at build/executable.swf. If you wish to make it available at package's root level, change the -C directive to the following:
-C ./../../build executable.swf

How do I find the packages defined in a jar?

I have a bunch of JAR files (from a maven2 project) and maven reports some package could not be found (org.openanzo.client.jena to be exact). I want to dig into the JAR files downloaded as the result of maven dependency resolution and find what packages are thus available from these JAR files. Insights?
UPDATE: Apparently, the only good solution to inspect insides of a jar file is the "jar" utility or one can use the facilities of their IDE to do so.
jar tvf filename.jar will show you the contents of a jar file without requiring you to extract it.
But I think that maybe what you are really trying to do is find the right coordinates for the dependency that you are missing, since obviously none of the ones you have right now are supplying the package you are looking for (in other words, checking their contents is not likely to help you).
I confess that the first place I would suggest to check is Sonatype's public Nexus instance. A search for your example turns up nothing, though. Usually that means the project is not trying to get their stuff into Maven Central or other major repositories (which is okay), so you have to resort to a web search. Usually the first two sections of the package tell you where to look (openanzo.org in your case).
If you are on Linux or a Mac, you could go to the terminal at the root of the folder containing your JARs and type:
# grep -ri "org.openanzo.client.jena" *
It will return a recursive list of all JAR files that contain that package name. If it returns 0 results, then none of those JARS contain that package.
If you wanted to do a more exhaustive search, you could unJAR the JAR files. The directory structure and .class files will be organized by packages in folders.
# jar xvf filename.jar
If you are on Windows, you can unJAR a JAR file using a tool such as 7Zip.
#Carsten
you do not have to rename a .jar file to .zip. You can directly open the jar file in winzip/or other zip utility (assuming windows OS)
#ashy_32bit
try using "jar class finder" eclipse plugin from IBM. Simple plugin for finding classes (if you know the class name)
OR
as carsten suggested... set the jar files as lib files and manually look it up
OR
create a batch file called a.bat (where you have all your jar files directly under a single folder) and paste the following 4 lines
#ECHO OFF
dir /b *.jar > allJarFilesList.txt
FOR /F %%A IN (allJarFilesList.txt) DO jar -tf %%A > list_of_packages.txt
FOR %%B IN (list_of_packages.txt) DO FIND /I "com/sun" %%B
NOTE the "com/sun" in the last line.. it is hard coded, you can pass as argument as well...
I know this is very basic form and can be improved "a lot" like looking up in various sub directories.
hope this helps :-)
.jar files are just ZIP compressed archives, rename it to zip, open it with your favourite unzip programm, and traverse through the directory.
If you add the jar file to a eclipse project, you can traverse through the lib in th project explorer.
HTH
Assuming maven downloaded the jar files,the files will be loaded in to a local repository.
You could use maven browser that comes packaged with Eclipse to browse and search for artifacts in your repository.(usually in userdir/.m2/repository)
Note:You can explore your repository directly if you want. You will understand the packages that were downloaded. But I suggest using the plugin.
If you are using Intellij IDEA, each project contains a tree called External Library that allows you to search and explore your libraries.

Resources