How to update java class dynamically at runtime (like hot deployment) - classloader

I'd like to update java classes dynamically at runtime (just like hot deployment) . Is there solution for that ? Thanks

The way to update a class that has already been loaded by the JVM is bytecode instrumentation. Java instrumentation agents can use methods redefineClasses and retransformClasses of the java.lang.instrument.Instrumentation class. Native agents can use respective functions RedefineClasses and RetransformClasses of the JVMTI API.

Related

Qt app with dynamic set of functionalities

Please let me present the idea. I would like to build a Qt app which allows the user to load functionality from a external file (.dll ?) while the app is running. The file could be downloaded from the internet.
I'm planning to build the user interface with QUiLoader and I think the functionality should come from such an external file. Does it make sense?
As an example, to begin with, I'm imagining to provide the user simple functionality like sum and multiplication. And other functionality should be provided afterwards.
Since I have no ideia where to begin (as the question might suggest), I'm here to ask for directions?
Yes, what you need is a plugin mechanism.
For developing a plugin, you should decide how those plugin to be load and to get information from plugin, i.e. you should define a interface first hand, by that interface, your program can communicate with plugins developed by others.

Play Scala - Native access

I am developing an web application using the Play framework in Scala language. In my application I have to access the native methods which is written in C++ and converted into .so by using swig.
My aim is to call the native method which is in .so file from the Controller class. I have searched in the internet, but I didn't get any documentation for this.
I have seen some links which is used by scala language.
https://code.google.com/p/scala-native-access/
https://code.google.com/p/bridj/wiki/Download#Specialized_subsets_(smaller_JARs_!)
https://github.com/xudongyang/scala-native-access
But they didn't mention how exactly use this in the Play framework.
Can anybody have the documentation for Play scala native access?
Can anybody have the sample applcation for the same?
Like in any JVM language, JNA/JNI gives you native access. Be aware that because of Play's use of class loaders, you'll need to make sure you access from the same class. See fail to load a native library using activator (Play Framework)
This is hard to answer in general. Play! is just a Scala library and framework, some any tool that allows you to use native calls in Scala will work similarly with play. From the first link that you pointed to, there are instructions to integrate with SBT (the Scala Build Tool) which also manages your Play framework. You will need to make the changes they mention to your build.sbt file which you can find in the top level of your Play project folder.

How to Determine What Classes are Loaded in Glassfish

Is there a way to get a listing of which classes (and how many of each) are currently loaded in Glassfish v3.1.2.2 either from within Glassfish itself or another tool?
I'd recommend that you look at Visual VM, with all the plugins installed. It'll show you objects created, all generations of heap, CPU, threads, and lots of good stuff.
I consider it indispensible for Java EE development.

Loading WinRT component without referencing the DLL/assembly

I have been experimenting with WinRT components using C#, C++/CX and WRL in C++. So far I managed to do everything I tried even if compared to COM some stuff have changed and are either confusing or frustrating.
The last thing I'm trying and that so far I couldn't do is a basic architecture pattern of COM. I simply want to create an instance of a WRL component without referencing the DLL in the project which is using the component. As far as I remember this is the basic behavior of COM, provide the GUID of the CoClass of the COM, the using program knows only about the interface and CoCreateInstance will dynamically loads the COM and create an instance attached to the interface you're requesting.
I cannot find how to do that with WRL. I have defined few simple interfaces and I cannot even find them in the registry. However as it is possible with COM to use object without the registry and that there is now window metadata I suppose that this is the reason.
Does someone out there knows if this is not a restriction of WinRT (which would make it a very poor architecture...) or in the case it is possible how to achieve late binding with WRL.
To make it clear, in the calling program I would like to only provide the information of the interface (this can be the .h) then I need to be able to create an instance of the WinRT component using its GUID or a moniker name. This is an architecture pattern I have used in C++/COM, C# and Java as you can write an application and support new features without touching a line of the application, not even recompiling it.
Thanks
O. Rouit
So far it's unclear what you're actually trying to do. WRL is just a C++ helper library for WinRT, if you're using C++ (think of it as WRL-is-to-WinRT-as-ATL-is-to-COM).
Let's take C++, since that's the 'most raw' and has no vm or runtime like C# or JS. You're trying to instantiate a WinRT object that you didn't link with? If so, that's simple - ActivateInstance(activateableclassid). The real question is what are you trying to instantiate? If it's a 1st party (inbox/Windows) component, it should just work. This is very much like COM, where there ACID is like a CLSID and ActivateInstance() is like CoCreateInstance().
If you're trying to instantiate a 3rd party WinRT component (not shipped w/Windows), it's a little simpler. The ONLY way to register 3rd party WinRT components is by including them in your package. Packages are isolated from each other, so you cannot have, e.g. AngryBirds deliver a FOO WinRT object and use it in an app in the Scrabble package. Unlike COM where registration is machine wide (or in the rare even you register under HKCU instead of HKLM, user-wide), WinRT 3rd party (package'd) WinRT objects are only registered for use by apps in that package.(1)
(1) That's a little white lie. Technically your application can instantiate WinRT components provided with Windows and WinRT components provided by packages in your package graph. You can make a Framework package which includes WinRT objects, and have your application's package dependent on that. Windows figures our your package depends on the framework and thus your 'package graph' has 2 packages in it -- your app's package and the framework package. BUT you cannot submit Framework packages to the Store. Local development and enterprise/side-loading deployments can do this (they don't go through the Store and thus don't need to meet Store submission criteria), but any application package submitted to the Store can only depend on the Windows provided frameworks (WinJS, VCLibs, PlayReady/DRM). That's how PlayReady works - it's a Framework package containing (among other things) some WinRT objects; if your application's package declares a on it your package graph will contain 2 packages (your app's package + playready's package), and ActivateInstance() can resolve ACIDs across the union of packages in your package graph.
There's a lot of protections built into the application model. This is one of them. This prevents 'COM Hell' and 'DLL Hell' - everything's fine, then 6 months later you install app Y and for no apparent reason app X no longer works. The new appmodel is designed to prevent that scenario.
Another protection is the limitation of where package'd WinRT objects can be found. Even if you put a file in your app's local folder (e.g. ApplicationData.current.localFolder), ActivateInstance() won't find it. WinRT doesn't look under AppData (or oodles of other places) for registered WinRT objects -- only those in your package graph (and 1st party (Windows) components provided with the OS, e.g. StorageFolder).
provide the GUID of the CoClass of the COM, the using program knows
only about the interface and CoCreateInstance will dynamically load
the COM and create an instance attached to the interface you're
requesting.
The WinRT equivalent is to provide the ACID of the runtimeclass of the WinRT [component], the using program knows only about the interface and ActivateInstance() will dynamically load the WinRT [component] and create an instance attached to the interface you're requesting.
The caveat is, the WinRT component's implementation must be registered in your package graph, i.e. must be listed in your app's package's AppXManifest.xml, or a dependency's AppXManifest.xml.
That's at the most raw level, if you deal directly with WinRT at the ABI level. C++ projections are equivalent, just more convenient syntax. The CLR and JS runtimes provide their own additions and variations of enforcement (e.g. search for "windows 8 javascript local vs web compartment") but they just further color the behavior. They can't overrule the underlying OS' baseline behavior.
As Damir noted
You won't be able to put new files to install folder any other way and
that's the only location from which executable code can be loaded by
the app.
"Executable code" comes in varying forms, depending on your definition.
WinRT components can be loaded from other places (Windows provided WinRT components, dependent packages e.g. the PlayReady framework package).
(Non-WinRT, non-COM) 'native' DLLs can be loaded from other places (executable's directory, System32, etc). See Search Order for Windows store apps.
.NET assemblies in DLLs have their own similar restrictions e.g. Assembly.Load().
Some people consider Javascript "code", and there's the whole local vs web compartment thing to further color where code can be resolved from.
As a general rule, you can dynamically load code in a variety of ways, but it needs to be known code. There's no supported way you can create e.g. a C++ app that will load DLLs (WinRT or non-WinRT) that's not known at Store submission time. You can write an app using optional (conditionally loaded) code, you can have 'plugins' -- but they need to be in your package when you submit to the Store.
You can't build e.g. Outlook as is today, where Outlook is submitted to the Store with an open-ended plugin model and sometime later install an OutlookNiftyCalendar add-on which Outlook could find and use. Not in Windows 8.
(there are some ways you can bend this rule a bit in a Javascript app via web compartment, but that's a complex topic in its own right, and even that has limits both hard and soft/policy. And irrelevant if you're not writing a Javascript applications)

Deploying application question (C++)

Does someone know if there is a way to pack everything-application related into one (single) exe-file?
My product is fully written in C++, has a lot of external plugins (dll) and some external data packages. It should be accessible using the network and without installation (launch in one click).
Are there some tools to make something like virtual filesystem and unpack everything application-related to memory?
Or probably I have to somehow (manually) integrate all the dlls and the data? Is this possible?
Thank you
Try an .msi file, or ClickOnce deployment (assuming Windows, assuming at least VS 2005).
Edit: Based on a comment below, I don't know in general if you can do exactly what you are asking with an arbitary set of DLLs. You can include, say, Microsoft Foundation Classes statically rather than dynamically. But the distributor of a DLL may not want to allow complete incorporation into your code. Even if you could, you might be running against license agreements and the like.
Not sure if that's what you want but UPX is made to generate a single exe from an application made of several ones : http://upx.sourceforge.net/
However if you want a virtual folder system, maybe you just need to use PhysicsFS ? http://icculus.org/physfs/
Anyway your question is not really clear...

Categories