open a specific eclipse project from command line - eclipse

I work with many small, but unrelated java projects. I made an Ant script that creates the .project and .classpath automatically whenever I create a new project, with the needed libraries and project name. I would like to be able to open Eclipse with that project, from the command line. Right now I do it manually, by closing the old open project in the workspace, then I do an Import and find the new project. I could not find a way to do this from either Ant or batch. I can open Eclipse, but it comes up with the last workspace/project. I don;t mind if I would have to create an individual worspace/project, but i don't know how to do that from a script. Thank you for any suggestions.

I would recommend against doing this as it is not really that much effort to import the project using the standard wizards. I'd focus on closing the inactive projects (see more below).
Edit: If you are dead set on using ant to bring the projects into the workspace, you can implement a plugin doing something like the code below.
Do you close the old projects or delete them? I don't see any reason to actually delete them. If you close all projects you aren't working on (right click on them and select close project or select the project you do want and right click->close unrelated projects), they are ignored by the platform so won't impact development of the open project.
To hide the closed projects from the view, you can click the downwards pointing triangle in the top right corner of the Package Explorer view, select Filters... and in the Select the elements to exclude from the view: list check the Closed projects option.
This is a plugin that will read a set of names from a file in the workspace root, delete all existing projects (without removing the contents) and create the new projects in the workspace. Use is at your own risk, no liability blah blah.
Take the contents and put them in the relevant files and you can package an Eclipse plugin. I'd recommend using a separate Eclipse install (actually I recommend against using it at all) as it will run every time it finds the newprojects.txt in the workspace root.
The declaration in the plugin.xml implements an Eclipse extension point that is called after the workbench initializes. The earlyStartup() method of the StartupHelper is called. It creates a new Runnable that is executed asynchronously (this means the workspace loading won't block if this plugin has issues). The Runnable reads lines from the magic newprojects.txt file it expects to see in the workspace root. If it finds any contents it will delete/create the projects.
Update:
The helper has been modified to allow for projects to be created outside the workspace, if you define a value in newprojects.txt it is assumed that is the absolute URI of the project. Note that it doesn't escape the string, so if you are on a windows platform, use double slashes on the path.
Example contents:
#will be created in the workspace
project1
#will be created at c:\test\project2
project2=c:\\test\project2
Good luck!
/META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Project fettling Plug-in
Bundle-SymbolicName: name.seller.rich;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: name.seller.rich.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.workbench;bundle-version="3.4.1",
org.eclipse.swt;bundle-version="3.4.1",
org.eclipse.core.resources;bundle-version="3.4.1"
Bundle-ActivationPolicy: lazy
/plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.startup">
<startup class="name.seller.rich.projectloader.StartupHelper"/>
</extension>
</plugin>
/.project:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>name.seller.rich.projectloader</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/.classpath:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/src/main/java/name/seller/rich/Activator.java:
package name.seller.rich;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends Plugin {
// The plug-in ID
public static final String PLUGIN_ID = "name.seller.rich";
// The shared instance
private static Activator plugin;
/**
* Returns the shared instance
*
* #return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
/**
* The constructor
*/
public Activator() {
}
#Override
public void start(final BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
#Override
public void stop(final BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
}
/src/main/java/name/seller/rich/projectloader/StartupHelper .java:
package name.seller.rich.projectloader;
import java.io.File;
import java.io.FileInputStream;
import java.util.Map;
import java.util.Properties;
import name.seller.rich.Activator;
import org.eclipse.core.internal.resources.ProjectDescription;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
public class StartupHelper implements IStartup {
private static final class DirtyHookRunnable implements Runnable {
private IWorkspaceRoot workspaceRoot;
private DirtyHookRunnable(final IWorkspaceRoot workspaceRoot) {
this.workspaceRoot = workspaceRoot;
}
public void run() {
try {
IPath workspaceLocation = this.workspaceRoot.getLocation();
File startupFile = new File(workspaceLocation.toOSString(),
"newprojects.txt");
IProgressMonitor monitor = new NullProgressMonitor();
Properties properties = new Properties();
if (startupFile.exists()) {
properties.load(new FileInputStream(startupFile));
}
if (properties.size() > 0) {
// delete existing projects
IProject[] projects = this.workspaceRoot.getProjects();
for (IProject project : projects) {
// don't delete the content
project.delete(false, true, monitor);
}
// create new projects
for (Map.Entry entry : properties.entrySet()) {
IProject project = this.workspaceRoot
.getProject((String) entry.getKey());
// insert into loop
ProjectDescription projectDescription = new ProjectDescription();
projectDescription.setName((String) entry.getKey());
String location = (String) entry.getValue();
// value will be empty String if no "=" on the line
// in that case it will be created in the workspace
// WARNING, currently windows paths must be escaped,
// e.g. c:\\test\\myproject
if (location.length() > 0) {
IPath locationPath = new Path(location);
projectDescription.setLocation(locationPath);
}
project.create(projectDescription, monitor);
// project.create(monitor);
project.open(monitor);
}
}
} catch (Exception e) {
IStatus status = new Status(IStatus.INFO, Activator.PLUGIN_ID,
0, "unable to load new projects", null);
Activator.getDefault().getLog().log(status);
}
}
}
public StartupHelper() {
super();
}
public final void earlyStartup() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
workbench.getDisplay().asyncExec(new DirtyHookRunnable(workspaceRoot));
}
}

Another possible option is given on this question. The essence of the answer is, if you have CDT installed, you can do:
eclipse -nosplash
-application org.eclipse.cdt.managedbuilder.core.headlessbuild
-import {[uri:/]/path/to/project}
-importAll {[uri:/]/path/to/projectTreeURI} Import all projects under URI
-build {project_name | all}
-cleanBuild {projec_name | all}
The trick here is that it can import any project, not only C projects.

Partial solution: Open eclipse in a specified workspace:
eclipse.exe -data c:\code\workspace-name

The full list of options is helpful as #Paul Wagland indicated, but I couldn't get it to work until I used this command which included the -data option:
user#devmachine:~/dev$ eclipse -nosplash -data /home/$USER/dev -application org.eclipse.cdt.managedbuilder.core.headlessbuild -import /home/$USER/dev/src_dir

Related

Which files has to be added in plugins to open the hadoop mapreduce source code in eclipse

Suppose I have written a follwing code in eclipse
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer
extends Reducer<Text,IntWritable,Text,IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context
) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCount.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Now, suppose I want to open the source code of Job/Configuration object(as obvious by clicking on it with ctrl pressed),eclipse throws error saying source code not found with Attach source tab.
I tried downloading few plugins but it din't work.
Please help,Thanks in advance.
(Note: I use eclipse mars,version 2.7.2 and OS is ubuntu 16.04 LTS)
The best way to set up Map-Reduce Projects in Eclipse is by using Maven.
First, setup a Maven Project in Eclipse.Follow this link : https://wiki.jasig.org/display/UPM32/Creating+a+Simple+Maven+Project
2.Next, update the pom.xml file of your maven project with the below tags. You can change the version tags for Hadoop related Artifacts according to your need (2.7.2 according to your question). Make sure JAVA_HOME is set in your system env variables.
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.8</version>//1.7 if you are using jdk 7
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.7.3</version>
</dependency>
</dependencies>
Right click on your eclipse project Go to Maven -> Click Update Project
and wait for a while. It will download all the dependent jars for executing a Hadoop Client.
4.Now, When you write your Mapreduce code, and try to view the source of any Class or Method(Job, in your case) Eclipse should not complain "source code not found with Attach source tab". You should be able to see the source code.

de.hybris.eventtracking.model.events.AbstractTrackingEvent cannot be resolved to a type

I just finished configuring hybris and tried to set up the eclipse project. As per guidelines in the wiki.hybris, I imported all the extensions into the eclipse project. When I try into build and clean, I get more than 3000 compiler errors. One of the errors is the class AbstractTrackingEvent cannot be resolved to a type. I looked for the particular class in the project folder. I could not find the folder events under de.hybris.eventtracking.model, which is the cause of the issue.
Am I missing anything while importing the project? There are many such type of issues in my eclipse project. Please let me know how to fix it. I have attached the screenshot for reference.
Note: I am using hybris-commerce-suite 5.7.0.8
As requested, I am adding the source code.
package de.hybris.eventtracking.services.populators;
import de.hybris.eventtracking.model.events.AbstractTrackingEvent;
import de.hybris.eventtracking.services.constants.TrackingEventJsonFields;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* #author stevo.slavic
*
*/
public abstract class AbstractTrackingEventGenericPopulator implements
GenericPopulator<Map<String, Object>, AbstractTrackingEvent>
{
private final ObjectMapper mapper;
public AbstractTrackingEventGenericPopulator(final ObjectMapper mapper)
{
this.mapper = mapper;
}
public ObjectMapper getMapper()
{
return mapper;
}
protected Map<String, Object> getPageScopedCvar(final Map<String, Object> trackingEventData)
{
final String cvar = (String) trackingEventData.get(TrackingEventJsonFields.COMMON_CVAR_PAGE.getKey());
Map<String, Object> customVariablesPageScoped = null;
if (StringUtils.isNotBlank(cvar))
{
try
{
customVariablesPageScoped = getMapper().readValue(cvar, Map.class);
}
catch (final IOException e)
{
throw new ConversionException("Error extracting custom page scoped variables from: " + cvar, e);
}
}
return customVariablesPageScoped;
}
}
"As per guidelines in the wiki.hybris, I imported all the extensions into the eclipse project."
I don't think the guidelines tell you this. Basically, you want the projects loaded to be the same as those defined in your localextensions.xml and their dependencies. The reason you can't see those is they are not built.
Ensure you have run 'ant build' successfully, refresh the platform project, remove any extensions from your workspace that are not needed for your project, and clean and build in eclipse.
Make sure you have provided the project dependencies in each project by checking their individual extensioninfo.xml files as shown in below image.
Also sometimes dependent libraries are not imported properly check for those too.

How to assign a shortcut key to run a particular EASE script

I am curious whether it is possible to assign a shortcut key to run a particular EASE script. I know that I can add scripts to UI, but for me applying of shortcut keys is more familiar and convenient way to do my work.
Maybe, first I should create a popup-menu item and then assign a key to the item. So I've added the context menu item but I can not find any reference to the item in Preferences>>General>>Keys.
I find out the way to run a particular EASE script typing a sequence of keys:
create an eclipse plugin project;
add extension points to define a key binding, a command handler and an ease module;
write a module class and a command handler class.
The command handler's method called "execute" is invoked when I type the sequence of keys. As I can use the module to access the command handler synchronously, so I can assign code to be run from within the "execute" method.
This is plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.ui.bindings">
<key sequence="Ctrl+Shift+D"
commandId="m5.command_0"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.jdt.ui.javaEditorScope"/>
</extension>
<extension point="org.eclipse.ui.commands">
<command name="Execute custom command"
defaultHandler="m5.handlers.CustomHandler_0"
description="Execute custom command"
categoryId="org.eclipse.jdt.ui.category.source"
id="m5.command_0">
</command>
</extension>
<extension
point="org.eclipse.ease.modules">
<module
category="org.eclipse.ease.category.system"
class="m5.handlers.Module1"
id="M5.module1"
name="M5.module1"
visible="true">
</module>
</extension>
</plugin>
This is the command handler:
package m5.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
public class CustomHandler_0 extends AbstractHandler {
private static Runnable runnable;
protected synchronized static void setRunnableToExecute(Runnable codeToRun){
runnable = codeToRun;
}
#Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
System.out.println("command_0");
if(runnable != null){
runnable.run();
}
return null;
}
}
This is the module:
package m5.handlers;
import org.eclipse.ease.modules.AbstractScriptModule;
import org.eclipse.ease.modules.WrapToScript;
import m5.handlers.CustomHandler_0;
public class Module1 extends AbstractScriptModule{
#WrapToScript
public void setCommand_0(String code){
CustomHandler_0.setRunnableToExecute(new Runnable(){
#Override
public void run() {
getScriptEngine().executeAsync(code);
}
});
}
}

Implement validator in Eclipse

I am trying to implement validation in Eclipse. My work has many little projects that serve to customize our product for various customers. Since there are a ton of developers we are trying to find a way to enforce various standards and best practices.
For example, we have many XML configurations that we want to validate. The built-in validators ensure files are well-formed and follow a schema, but we would like to add validations such as checking that a Java class referenced in XML actually exists on the classpath. Another example is validating that a Java class implementing a certain interface does not have any object variables (i.e. the code needs to operate only on parameters and not maintain state).
It appears that there are two ways to add validation. The first is through a builder which adds markers. The second is through stand-alone validation. However, we are not actually building anything, and I have not found any useful tutorials or examples on validation (does not help that help.eclipse.org is currently being moved and is unavailable).
When I right-click a test project and select "validate" I get a message stating there was an error during validation, and my test message does not show up in the problem view. However, there are no errors in the Eclipse log. The host Eclipse shows nothing in the console. No exceptions logged anywhere, and no message. The project does have the required custom nature.
I was following these instructions but there is no code or fully functioning example, and Google has not been kind enough to fill in the blanks. Combined with the Eclipse help site being down right now, I am at a loss as to how to proceed.
plugin.xml:
<plugin>
<extension name="My Validator" point="org.eclipse.wst.validation.validator"
id="com.mycompany.pluginname.validator.MyValidator">
<validator>
<projectNature id="com.mycompany.pluginname.nature.MyNature"/>
<helper class="org.eclipse.wst.validation.internal.operations.WorkbenchContext"/>
<markerId markerIdValue="com.mycompany.pluginname.validator.DefaultMarker"/>
<run class="com.mycompany.pluginname.validation.validator.MyValidator"/>
<runStrategy project="true"/>
</validator>
</extension>
<extension point="org.eclipse.core.resources.markers" name="My Validator"
id="com.mycompany.pluginname.validator.DefaultMarker">
<super type="org.eclipse.core.resources.problemmarker"/>
<persistent value="true"/>
<attribute name="owner"/>
<attribute name="validationSeverity"/>
<attribute name="targetObject"/>
<attribute name="groupName"/>
<attribute name="messageId"/>
</extension>
</plugin>
Validator code:
package com.mycompany.pluginname.validation.validator;
import org.eclipse.core.resources.IProject;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.operations.IWorkbenchContext;
import org.eclipse.wst.validation.internal.provisional.core.*;
import com.mycompany.pluginname.validation.plugin.ValidationPlugin;
#SuppressWarnings("restriction")
public class MyValidator
implements IValidator {
#Override
public void cleanup(IReporter argReporter) {
argReporter.removeAllMessages(this);
}
#Override
public void validate(IValidationContext argContext, IReporter argReporter)
throws ValidationException {
String bundle = ValidationPlugin.getDefault().getTranslationsBundleName();
IProject prj = ((IWorkbenchContext) argContext).getProject();
String[] attributes =
new String[] {"owner", "validationSeverity", "targetObject", "groupName", "messageId"};
IMessage msg = new Message(bundle, IMessage.HIGH_SEVERITY, "test", attributes, prj);
argReporter.addMessage(this, msg);
}
}
I also find it odd that adding validation would require using restricted packages and interfaces. It also seems odd that it wants an IMessage rather than an IMarker.
I did look at Eclipse plugin with custom validation which seems to be oriented around creating a new editor, where I want to validate files regardless of the editor used (in fact I do not want to create an editor).
Edit: I updated to use the V2 framework, but nothing appears in the problem view. What am I doing wrong? Is there a tutorial somewhere that explains how this works? I was able to figure out the following, but obviously it is not correct:
public ValidationResult validate(ValidationEvent argEvent, ValidationState argState,
IProgressMonitor argMonitor) {
final IResource resource = argEvent.getResource();
final ValidationResult result = new ValidationResult();
try {
List<String> contents = Resources.readFile((IFile) resource);
for (int i = 0; i < contents.size(); ++i) {
int offset = contents.get(i).indexOf("bad_string");
if (offset >= 0) {
result.add(ValidatorMessage.create("Found bad string", resource));
result.incrementError(1);
}
}
}
catch (Exception ex) {
result.add(ValidatorMessage.create(ex.getMessage(), resource));
}
return result;
}
I admit this is a stab in the dark: the documentation is not very descriptive and I have not found any tutorials on this V2 validator. Oh, I have a filter on this validator so it only receives specific XML files, which is why there is no input validation.
Also, since I am a pedant myself, I am using the old-style for loop there because I expect to show the line number with the error to the user. But obviously I am not quite there yet.
Another edit: here is the working code. The only issue is the squiggly is not on the correct line because the offset is from the start of the file, not the line. But it does work:
public ValidationResult validate(ValidationEvent argEvent, ValidationState argState,
IProgressMonitor argMonitor) {
final IResource resource = argEvent.getResource();
final ValidationResult result = new ValidationResult();
try {
List<String> contents = Resources.readFile((IFile) resource);
int location = 0;
for (int i = 0; i < contents.size(); ++i) {
int offset = contents.get(i).indexOf(CONSTANT);
if (offset >= 0) {
ValidatorMessage vm = ValidatorMessage.create("Message", resource);
vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
vm.setAttribute(IMarker.SOURCE_ID, IMarker.PROBLEM);
vm.setAttribute(IMarker.LINE_NUMBER, i + 1);
vm.setAttribute(IMarker.CHAR_START, location + offset);
vm.setAttribute(IMarker.CHAR_END, location + offset + CONSTANT.length());
result.add(vm);
}
// TODO: account for different line endings.
location += (line.length() + 2);
}
}
catch (Exception ex) {
ValidationPlugin.getDefault().warn(ex);
result.add(ValidatorMessage.create(ex.toString(), resource));
}
return result;
}
Plugin.xml:
<extension name="My Validator" point="org.eclipse.wst.validation.validatorV2"
id="com.company.plugin.validation.validator.MyValidator">
<validator class="com.company.plugin.validation.validator.MyValidator">
<include>
<rules>
<file type="file" name="FileName.xml"/>
</rules>
</include>
</validator>
</extension>
I actually found another SO question along these lines that corroborates what I found: Setting IMarker.CHAR_START and IMarker.CHAR_END attributes for IMarkers Annotations
sigh that document is very out of date. You should use the org.eclipse.wst.validation.validatorV2 extension point, extending the newer org.eclipse.wst.validation.AbstractValidator class.

Spring bean loading issue in BIRT designer

I have an issue with Spring not loading beans correctly when run from a script in a BIRT Scripted Data Source, but running OK on its own.
Here's a minimal test case:
The spring bean:
package test;
import org.springframework.stereotype.Component;
#Component
public class TestComponent { }
The context provider:
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringContextHolder {
private static ApplicationContext ac;
public static ApplicationContext getApplicationContext() {
if( ac == null ) {
ac = new ClassPathXmlApplicationContext("classpath:beans.xml");
}
return ac;
}
}
beans.xml:
<beans .......>
<context:component-scan base-package="test"></context:component-scan>
<context:annotation-config />
</beans>
And finally the test program which is a simple Eclipse java project having all spring and related jars and the test.jar from above in its build path:
public class cltest {
public static void main(String[] args ) throws BeansException {
System.out.println(test.SpringContextHolder.getApplicationContext().getBean("testComponent"));
}
}
This program runs fine and delivers the bean. But when I run the same jars in BIRT designer (4.3.0) by setting them in the Report classpath preferences, I get an exception:
A BIRT exception occurred. See next exception for more information.
Wrapped org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/C:/Users/xxx/.m2/repository/test/test/0.0.1-SNAPSHOT/test-0.0.1-SNAPSHOT.jar!/test/SpringContextHolder.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 6
The script source is simply:
importPackage(Packages.test);
ts = SpringContextHolder.getApplicationContext().getBean("testComponent");
The exception results from org.springframework.asm.ClassReader where a readShort violates some array boundaries.
Spring version is 3.2.3 RELEASE, Oracle Java 7u25, BIRT Designer 4.3.0.
Can anyone explain what the difference between the two running scenarios is? Probably some class loader issues when the jars are loaded by the eclipse runtime?