OSGI - get class name in a bundle - apache-karaf

For one of a monitoring project I need to find out the class names available in a OSGI bundle (apache Karaf). I checked in the bundle and bundleContext class, but could not find any relevant methods to get the class names. Please help!!
PS - i can get the list of classes using bundle:class command. But i would like to get from the code.
EDIT - It is not 1 bundle for which i need to know, i want to run the code in any karaf environment to find all the bundles and also class names in those bundles.

You can simply do the same that apache karaf does See the source of the classes command:
https://github.com/apache/karaf/blob/master/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java

Related

Where is API Platform config for entity mapping is situated in the latest versions?

The documentation says that there is file api/config/api_platform/resources.yaml where I can map entities using yml. But neither in the distribution nor when I install API-platform as a package I can't find this file. Creation of the directory and file manually doesn't help.
In the context of a Symfony 4 project, the file can be located at config/api_platform/resources.yaml. If it doesn't exist, simply create it.
You can also use several files in order to define your mappings:
config/api_platform/resources/entity1.yaml
config/api_platform/resources/entity2.yaml
I suggest to use separate files since it's simpler to maintain than one big file.
You'll have to configure these paths in the config/packages/api_platform.yaml file:
api_platform:
mapping:
paths: ['%kernel.project_dir%/config/api_platform/resources']
See Nek's answer for a complete example.
I find the documentation a little bit confusing about this, because in a Symfony project there's no api/ directory at the root of the project.

How to refer some classes of a bundle in a non-osgi environment?

I have made some jars in a bundle. For example: a.jar, b.jar, a.jar has class named some.pkg.SomeClass.
I writed MANIFEST.MF file like below:
Bundle-ClassPath: lib/a.jar,
lib/b.jar
Export-Package:some.pkg
I export the jar with name ab.jar,and it worked in an osgi environment.But in a non-osgi environment, when I refer this class some.pkg.SomeClass, it failed!
So how can I refer this class some.pkg.SomeClass in a same jar not only in an osgi environment but also in a non-osgi environment?
If you package jars inside the ab.jar then it is not possible to access these outside of OSGi.
An alternative is to use the maven shade plugin to extract the classes from both jars and package the classes in the ab.jar.

sbt-native-packager include different application.conf depending on parameter

I have a simple sbt application that uses typesafe-config library and is build using sbt-native-packager.
I build it using following command:
sbt universal:packageBin
Within the src directory I have following hierarchy:
main/resources/application.conf
test/resources/application.conf
staging/resources/application.conf
And my archive always ends up containing only the main version of application.conf
I'm looking for a easy way to include specific application.conf file based on for example java property passed during project build, but I'm unable to find anything.
Have you taken a look at the mappings facility, which allows you to add/remove files from the base layout? See Change-Remove Top Level Directory In Output in the official docs.

Symfony2 - Target directory changed when generating a bundle

I've noticed this recently, from a clean install of Symfony2 and removed AcmeDemoBundle (from the AppKernel, routing_dev.yml etc.). I generate the bundle and noticed that the Target directory for the bundle has changed and every time I create a new bundle I have to manually put in the proper path to it. Seems to be a problem with the latest release of Symfony2.
Changed Target directory line during bundle creation:
Target directory [/var/www/html/Project/app/cache/dev/../src]:
The path that it use to point was:
Target directory [/var/www/html/Project/src]:
I am at a loss for what changed as I installed a clean build and did not alter any settings.
When I installed Symfony2 I used the following: (which is the same way I've used previously)
composer create-project symfony/framework-standard-edition Project #stable
php app/console generate:bundle (see last line)
Welcome to the Symfony2 bundle generator
Your application code must be written in bundles. This command helps
you generate them easily.
Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).
See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.
Use / instead of \ for the namespace delimiter to avoid any problem.
Bundle namespace: Foo/FooBundle
In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest FooFooBundle.
Bundle name [FooFooBundle]:
The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.
Target directory [/var/www/html/Project/app/cache/dev/../src]:
Fixed by updating composer:
composer self-update
Then creating a new project.

Symfony 2 - How to determine the namespace and Bundle name for autoload.php & Appkernel.php

I'm very new to symfony2 and I cannot find this info:
To register a bundle located in my vendor dir, how to determine the namespace and Bundle name for autoload.php & Appkernel.php?
For example, I have downloaded Luiggio's PHPExcel Bundle. I have place it in vendorDir/ExcelBundle/
Where content is:
namespace Liuggio\ExcelBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class LiuggioExcelBundle extends Bundle
{
}
What lines should I put in Appkernel and namespace.php?
This and this does not work:
new Liuggio\ExcelBundle\LiuggioExcelBundle()
//'Liuggio\\ExcelBundle' => array($vendorDir. '/PHPExcel'),
I cannot use composer or github repo at all, too many proxies and restrictions where I am.
You shouldn't place bundles in your vendor directory manually. Let Composer do this for you. Not only does Composer know where vendor libraries / bundles should be located, it also adds them to your autoload files and performs some other automated tasks.
To tell Composer which libraries are required, you should add them to your composer.json:
"require" : {
(...)
"liuggio/ExcelBundle": "~2.0"
},
Next, using the command line, run the composer update command:
$ php composer.phar update
(if you don't have a file composer.phar in your project directory, but you have Composer installed globally instead, use the following:)
$ composer update
This will tell Composer to download the required dependencies, update the autoload script, etc, all automatically. When it's finished, you're ready to go.
If you can't use Composer on your server, then run it locally before you upload your files (although I strongly recommend moving to a server that does allow you to use Composer).
The line you're trying to add to AppKernel.php is correct, however it only works after running Composer (or you'd indeed have to download the files and update the autoloader manually, but I'd strongly recommend against that).
Edit
If you really can't use Composer, do the following:
Place the files of ExcelBundle in the following directory:
vendor/liuggio/ExcelBundle/Liuggio/ExcelBundle
Your line in AppKernel.php was already correct.
Add this line to autoload_namespaces.php:
'Liuggio\\ExcelBundle' => array($vendorDir . '/liuggio/ExcelBundle'),
Last but not least, complain to your system administrator that he's making your work impossible with his stupid security measures.
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
in AppKernel should be working fine.
This is the namespace of the LuiggioExcelBundle class + the class name. Look how your bundles are loaded, its the same.
What's your error?
You say vendorDir/ExcelBundle/ but its vendor/ExcelBundle right?
And what do you mean by namespace.php? :o
https://github.com/liuggio/ExcelBundle ==> there readme is rly easy to understand, it should help you.
For your "proxies and restriction", composer is a powerful tool, I can help you to use it. Download this soft, the free version is enough http://www.frozenway.com/ (if you cant read french, the 1st input in the header is to translate the website, English is Anglais) With this, you wont have any ports restriction.

Resources