Adding a nature on a custom project within an Eclipse plugin fails - eclipse-plugin

I'm developping a plugin to implement a custom project kind with custom nature and builder. Within a new wizard, I execute the following code to create the project:
IProject newProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
IProjectDescription desc = newProject.getWorkspace()
.newProjectDescription(newProject.getName());
desc.setLocationURI(projectLocation);
try {
newProject.create(desc, null);
if (!newProject.isOpen()) {
newProject.open(null);
}
} catch (CoreException e) { (...) }
Now the project is created, I try to add the nature with the following code:
if (!project.hasNature(MyNature.NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = MyNature.NATURE_ID;
description.setNatureIds(newNatures);
IProgressMonitor monitor = new NullProgressMonitor();
project.setDescription(description, monitor);
}
Here is the content of my plugin.xml file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Eclipse
Bundle-SymbolicName: com.myapp.eclipse;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.myapp.eclipse.Activator
Bundle-Vendor: MyApp
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources;bundle-version="3.6.1",
org.eclipse.ui.ide;bundle-version="3.6.2"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: com.myapp.eclipse,
com.myapp.eclipse.builder,
com.myapp.eclipse.nature,
com.myapp.eclipse.saving
All these codes partially work since the project is actually created but there is no .project file within it. I can't see any error.
What did I do wrong and how can I debug the problem?
Thanks for your help.
Thierry

I think this may be because you are setting the project location in the project description. Instead of
desc.setLocationURI(projectLocation);
call
desc.setLocation(null);
The location in the description should only be set if it is not the default.

Related

How to add SolanaKT to my project kotlin?

I have an existing kotlin project. Now I'm trying to add the SolanaKT library to it.
I have added the JitPack repository maven { url 'https://jitpack.io' } and dependency implementation 'com.github.metaplex-foundation:SolanaKT:2.0.1'.
Then I did a gradle sync.
I try using:
val endPoint = RPCEndpoint.devnetSolana
val network = HttpNetworkingRouter(endPoint)
val solana = Solana(network)
But i get error Unresolved reference: RPCEndpoint.
What am I doing wrong? Is there anything else I should do (maybe copy some files to the project) ?

Force the usage of a bin folder

I have a larger ASP.NET Core project which means that a lot of DLLs are included in the publish.
Since all of the DLLs are placed in the root folder it's cumbersome to navigate the folder structure (to mange configs etc) due to the sheer amount of files.
Is it possible to tell ASP.NET Core that it should load all assemblies from another folder (bin\)?
I would do it in opposite side. If your problem is just config files then relocate them into config folder and keep them there. As of now dotnet will publish your project + framework (if you use self contained flag).
You can configure aspnetcore to use files
config.AddJsonFile("config/appsettings.json", optional: false, reloadOnChange: false);
So then that folder will be on top and better accessible
Yes in root folder there still be web.config but in my project that file usually is same for all environments. But again it depends where you deploy, because if you deploy to non IIS environment then you don't even need it
Hi How about the Managed Extensibility Framework , It allows you load assemblies dynamically.
Use BuildManager to load assemblies dynamically,
string pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
foreach (string f in Directory.GetDirectories(pluginPath))
{
string binPath = Path.Combine(f, "bin");
if (Directory.Exists(binPath))
{
foreach (String file in Directory.GetFiles(binPath, "*.dll"))
{
Assembly a = Assembly.LoadFrom(file);
BuildManager.AddReferencedAssembly(a);
}
}
Resolve assemblies using below code,
protected virtual void Application_Start(object sender, EventArgs e)
{
//...
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in currentAssemblies)
{
if (assembly.FullName == args.Name || assembly.GetName().Name == args.Name)
{
return assembly;
}
}
return null;
}

View pdf in JPanel

How to view the pdf in JPanel using PDfBox??
I have the Source Code Like below.
try {
PDDocument inputPDF = PDDocument.load(FilePath);
List<PDPage> AllPages = inputPDF.getDocumentCatalog().getAllPages();
inputPDF.close();
PDPage TestPage = (PDPage)AllPages.get(0);
PDFPagePanel pdfPanel = new PDFPagePanel();
pdfPanel.setPage(TestPage);
pnlRiwayatStatus.add(pdfPanel);
}
catch(Exception e){
Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, e);
}
But thus source code NoClassDefFoundError
The missing class is mentioned in a comment:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
This shows that you don't have the Apache Commons Logging jar in your class path.
According to the PDFBox web site, though, it is a required dependency:
Minimum Requirements
PDFBox has the following basic dependencies:
Java 6
commons-logging
Commons Logging is a generic wrapper around different logging frameworks, so you’ll either need to also use a logging library like log4j or let commons-logging fall back to the standard java.util.logging API included in the Java platform.
You should consider using Apache Maven for automatic dependency resolution.

Velocity Unable To find Resources

This question is already asked but i am trying the same thing that is in accepted answer
protected static final String RESOURCE_LOADER = classpath.resource.loader.class";
static {
System.out.println("Velocity Initialization Started");
velocityEngine = new VelocityEngine();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty(RESOURCE_LOADER,ClasspathResourceLoader.class.getName());
try {
velocityEngine.init();
} catch (Exception e) {
LOG.error("Failed to load velocity templates e={}", e);
}
}
my velocity file is in
src/main/resources/velocity/templates/command/name.vm
i am getting templates by following command
template = velocityEngine.getTemplate("velocity/templates/command/GenericState.vm");
It works locally but when bundled in jar it does not work , I have examined the jar it consist of velocity folder
i am using velocity to generated java code
I am having maven project setup and maven is creating jar
try this way it should work.
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class,file");
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "VELLOGGER");
velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
velocityEngine.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
velocityEngine.init();

Can't access properties file

I've made a plugin from external jar. In this jar there is access to properties file:
final Properties properties = new Properties();
final String fileName = "/" + thisClass.getName() + ".properties";
InputStream inputStream;
try
{
inputStream = thisClass.getResourceAsStream(fileName);
properties.load(inputStream);
}
In my RCP-Application the inputStream is null. I've also exported the default package in the plugin. What's wrong.
I've solved my problem. The solution is to make an Eclipse-BuddyPolicy Entry to the Manifest.mf of the plugin with the external jar.
Eclipse-BuddyPolicy: global
This is described in the Eclipse Help: Platform Plugin Developer Guide-->Reference-->Other reference information-->Third party libraries and classloading