Packages in Java / intellij - intellij-idea

This is more an question about intellij (I think).
Recently updated my intellij and some of my prferences have been changed
when a class is put into a package it can no longer access any other classes, When starting a new project I have clicked auto import as always but it will not allow me to extend a class from an abstract class without both classes being at the same level.
Also when starting a new project a java module is no longer generated.
problem
Thank you for your help in advance (If you have not already guested I am farily new to programming)

You cannot import a Class from the default package.
Move the Player class into a package and everything will work fine.
See: What's the syntax to import a class in a default package in Java?

Related

ByteBuddy: Workaround for modifying schema of loaded class

The issue: We generate classes using ByteBuddy, load them and at one point will need to add/remove fields without re-starting the application.
If I understand correctly, in Java it is not possible to modify the schema (add fields/methods) of a class already loaded into a class loader.
My question: As a workaround, would it be a possible/reasonable to create a new class loader when a such a conflict occurs - load all generated classes into the new class loader and close the old class loader?
Thank you.
There is a VM version of OpenJDK that supports such transformations, the Dynamic Code Evolution VM.
For a regular VM, you can load a class in a new class loader. However, in this case no previous instance will be an instance of this altered class. You would need to recreate all instances. If this is feasible for you, this is an option.

Microsoft.AspNet.Identity.Owin.OwinContextExtensions doesn't seem to work

I am creating a custom asp.net.identity provider in a separate assembly in order to use it from two different web api 2 projects.
I took the default vs2013 template for a web api project as a guide and so far I have implement the required classes.
In the separate assembly I am using a user manager class derived from Microsoft.AspNet.Identity.UserManager(Of T) class.
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
Now I want to implement the create shared function in order to use as a callback in the CreatePerOwinContext function. According to the template, I am declaring it like this:
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.Owin
Imports Microsoft.Owin
Public Class EzeUserManager
Inherits UserManager(Of EzeIdentityUser)
... Class Implementation ...
Public Shared Function Create(options As IdentityFactoryOptions(Of EzeUserManager), context As IOwinContext)
Dim Result As New EzeUserManager(New EzeIdentityUserStore(context.Get(Of EzeLDAPContext)()))
The problem is that
context.Get(Of EzeLDAPContext)()
fails because it requires a key.
From the template I can see that the get method which doesn't require a key is an extension defined in Microsoft.AspNet.Identity.Owin.OwinContextExtensions which I have already installed and referenced through nuget and imported it in the class.
But it doesn't work.
I found that the key is actually the type name of the class so probably I can overcome this problem, however I didn't try it yet because I really want to make the extensions to work.
The question is: Am I missing something here?
Notes: The project in question is a Class Library targeting .NET 4.5.1 with the following references:
Microsoft.AspNet.Identity.Core
Microsoft.AspNet.Identity.Owin
Microsoft.Owin
Microsoft.Owin.Security
Microsoft.Owin.Security.Cookies
Microsoft.Owin.Security.OAuth
Newtonsoft.Json
Owin
As I explained in the question, I was using the template generated by VS as a guide. During the implementation process of my project, I had update the nuget packages several times but only in my project not in the template project (same solution) since I was going to deleted it afterwards. This resulted the two projects to reference two different versions of the required assemblies.
I don't know how exactly and why this "multi" reference caused this problem but once I updated the template project's nuget packages the problem was resolved.
I hope this helps someone with a similar issue.

Warnings while using a plugin and static library in a cocoa project

I have a scenario where I need to use a plugin as well as a static library into my xcode project. The plugin will be dynamically loaded into the system. Now, the static library is also getting used in creation of the plugin.
While executing my project I am getting a warning saying :
Class A is getting referenced from /staticLibraryPath and plugin. One of them will be used.
Please let me know, how to resolve the warning or a better way of implementing the scenario.
The issue is a name class of the two ClassA types found in both plugin and library
I assume you have control over the source of either plugin / library.
.. rename Class A in one instance to make the names not clash -- I don't think there is another way to get rid of the warning/error

Save and Load instances of objects created earlier via the Eclipse registry

I am currently experiencing a problem in my RCP application and wanted to ask, if someone stumbled over the same problem and can give me some valuable hints:
My RCP application allows plugins to provide implementations of a specific abstract class of my model (singleton) to extend my model during runtime via the update manager. I instantiate these classes via
extensionPointImplementation.createExecutableExtension(..)
after parsing the Eclipse registry. I can serialize the created instances using the default Java serialization API.
Now to the problem: The plugin trying to deserialize the objects cannot find the class implementations of the model extensions due to the fact, that there is no plugin dependency between the plugins. Nevertheless, it is not possible for me to create such a dependency which would make the idea of extending the model during runtime obsolete.
Is it possible to solve this problem by using the default Java serialization API or do I have to implement my own serialization (which parses the Eclipse registry and creates the instances via the line shown above if all necessary plugins are available, otherwise throw an exception) which might be based on the default Java serialization API (if possible I do not want to create the serialization completely by myself)?
Thanks.
You need to define a so called buddy policy.
In the bundle trying to instantiate the class add
Eclipse-BuddyPolicy: registered
to the manifest.mf.
In the bundle providing the class add
Eclipse-RegisterBuddy: <symbolic name of the bundle instantiating the class>
to the manifest.mf.

Scripting Eclipse with Rhino: classloader belongs to the plugin providing Rhino, not the plugin using it

I am using Rhino to script an Eclipse (RCP) application. The problem is that from Javascript I only have access to classes available to the plugin that provides Rhino, and not to all the classes available to the plugin that runs the scripts.
The obvious answer would be to put Rhino in the scripting plugin, but this doesn't work because it's already provided by one of the application's own plugins (which also provides things I need to script) and Eclipse always uses this version instead of the version closer to hand.
Is there a way to change the classloader used by Rhino
or is it possible to ensure that Eclipse loads the Rhino classes from one plugin rather than another?
Thanks to Thilo's answer I used this:
import net.weissmann.tom.rhino.Activator; // Plugin activator class
import org.mozilla.javascript.tools.shell.Main;
public class JSServer extends Thread {
//[...]
public void run() {
// recent versions of the Main class kindly export
// the context factory
Main.shellContextFactory.initApplicationClassLoader(
Activator.class.getClassLoader()
) ;
//[...]
}
Is there a way to change the classloader used by Rhino
Rhino should be using the current Thread's ContextClassLoader. Try Thread.setContextClassLoader (don't forget to restore it).
If that does not work, maybe you can create your own Rhino ContextFactory:
public final void initApplicationClassLoader(java.lang.ClassLoader loader)
Set explicit class loader to use when searching for Java classes.
I don't know Rhino specifics, but you could consider using Eclipse "buddy classloading" with the "registered" policy.
Rhino's plug-in (net.weissmann.tom.rhino, say) would declare itself "open to extension" by specifying Eclipse-BuddyPolicy: registered in its MANIFEST.MF. Plug-ins with classes that Rhino should be able to see would specify Eclipse-RegisterBuddy: net.weissmann.tom.rhino and would need a bundle-level dependency on net.weissmann.tom.rhino.
http://www.eclipsezone.com/articles/eclipse-vms/
http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements#Technical_Solution