How to keep M2_REPO variable dynamic in Aspect Path of an Eclipse Java/AspectJ run configuration? - eclipse

I'm trying to create a "Java/AspectJ application" run configuration for my Maven built project. Because i'm using Spring aspects i have to include the spring-aspects artifact in the run configuration's Aspect Path list. I'm adding it via the "Advanced.." button selecting "Add Classpath variable" and extending from the M2_REPO variable. So in the end i have a classpath variable entry in the list like this with a blue dot icon next to it:
M2_REPO/org/springframework/spring-aspects/3.1.3.RELEASE/spring-aspects-3.1.3.RELEASE.jar
However once i save it, Eclipse automatically replaces it in the launch file with the real path of the JAR on my machine making impossible to share the launch file with others since it's hard coding the entry to my environment.
Editing the launch file by hand doesn't help either because once i run it Eclipse replaces the expression the same way as above.
Is there any way to solve this?

The solution was to create the entry under the "Aspectj Load-Time weaving application" run configuration category instead of the "Aspectj/Java Application". For some strange reason the path of the Aspect is kept in it's unresolved format only with the first run configuration type. I guess it's a bug.
Obviously this makes the launch time longer because it does the waving in run time aswell. However i can't seem to find other solution.

Related

Set a classpath just for jUnit in Netbeans [duplicate]

We have an application developed in NetBeans, based on the NetBeans platform. There's a 3'rd party program that we have a runtime dependency on, more specifically a jar in the other progams lib folder.
How should we include the other progam's jar in our classpath?
The recommendation from the other progam's manufacturer is to set environment variable CLASSPATH to include
C:\Progam Files\Other Program\lib\theJAR.jar
And if that's not possible, we should copy theJAR.jar to JRE-HOME\lib\ext
We must not copy theJAR.jar anywhere else, that might cause it to stop working...
Now NetBeans takes no notice of what's on environment variable CLASSPATH. Their recommended way seems to be to make a wrapper, but that would lead to copying the jar, unless there's some way to make a wrapper module that points to CLASSPATH?
At the moment we are copying the jar into JRE-HOME\lib\ext. But then there's unnecessary hassle when we install some java update.
Do you have any solution to this problem? It seems like something that might be simple, but I haven't found the right place to look yet...
Edit: The application is ant-based.
From the documentation for the Module System API's overview of the runtime infrastructure (bottom of the page under the section "Common Problems and Solutions"):
Q: Can my module add a library JAR to the classpath from outside the
IDE [read: platform] installation?...
A: Not easily. You have a few options:
Add an entry to ide.cfg [your app's .config file]. For example:
-cp:a c:\eak\lib\eak.jar This startup file provides the ability to add classpath entries to the IDE's Java invocation.
...
It goes on to list two more options. The second option is the same solution you've come up with. The third is to "partition your module and use a new classloader" which I can't recommend either way since I have no experience doing this (but it's worth a read).
Assuming that this first option is what you are looking for, you will need to add a custom .conf file to your project and point to it in your project.properties file, like so: app.conf=nbproject/my.conf. This will add your custom .conf file to your app's install directory instead of the default config file that is normally added. Of course, you'll need to add the -cp:a c:\eak\lib\eak.jar entry to this custom config file in order to load the .jar.
During development you'll need to add the following entry to the project.properties file: run.args.extra=-cp:a c:\eak\lib\eak.jar. This will pass the command line option to your debug instance.
You can add that .jar file by following the steps below:
In the left side panel named "Projects" open your project and right click on the "Libraries", then select "Add JAR/Folder...".
Then select your .jar file from the location where you have stored it in the next dialog box that opens and then press "Open".
Vola Finished!!! (with the same process you can add other libraries also like JavaCV, JMF,etc)
And Now You Can Use That .Jar File From Your Project Library.
Hope It Helps.

Referencing a GWT project from another GWT one - Problems

I am already using an open source GWT project (iServe) and I would like to integrate into it another open source GWT project (PetalsBPM), by which I mean being able to call it and reference its methods.
I have imported iServe in Eclipse (it has multiple modules) as separate Maven projects referencing its other and can run it successfully through Runas -> Web application in development mode.
If I do that and run the other project through the console as mvn gwt:run, I call initiate PetalsMBP through iServe. However, that means that the two programs have to run as is, without communication with each other.
I have also imported the second project into eclipse as a java project successfully (converting into a Maven one causes problems - various lifecycle configurations ones), but whenever I try to add to to iServe through Properties -> Java Build Path -> Projects, although it does not cause any errors immediately, I cannot launch iServe anymore. It produces the following error:
"Exception occurred executing command line.
Cannot run program "C:\Program Files\Java\jre7\bin\javaw.exe" (in directory "C:...iserve-sal-gwt-1.0.0-SNAPSHOT"): CreateProcess error=206, The filename or extension is too long"
Are my problems related to the fact that PetalsBPM is not a Maven project in Eclipse (I doubt it)?
Am I doing something wrong, i.e., this is not the way to reference a project from another one? should I add a reference to the first project's (iServe) gwt.xml file?
Is there a way to do what I want without having to wrap the second project as a jar and calling it from iServe? I would prefer not to, since producing a jar every time I make a slight change is not exactly efficient!
P.S: The second project is a regular GWT project with an entrypoint, not just a module. Should I remove this?
UPDATE: Trying to figure out the source of this error, I attempted to simplify the problem, so I performed the following moves:
I created two new simple GWT projects and tried to reference one
from the other. Worked fine
I referenced the project I actually want
to use (PetalsBPM) from the simple one I just created. Also works
fine.
I referenced the new simple project from the original one I
want to use (iServe). Also works fine.
Tried doing what I actually
want to do, copying the settings from 2&3. Produces the same error
"CreateProcess error=206, The filename or extension is too long" if
I reference PetalsBPM (does not when I remove it from the referenced
projects)
So, I tried switching workspaces. I created a new workspace in C:\, and moved the actual projects there. Still it did not work. :(
Any more ideas?
I met the same type of error "Create Process, error=206, path too long etc." a hundred times.
Then, I found a solution/explanation in google-groups, it solved my problem.
I post the content and link as it might help others.
This website (StackOverflow) really helped me a thousand times.
Thanks to you all !
solution/explanation :
(Response from Stephen Johnson)
(...) if you're using eclipse plugin go to Project | Properties, choose
Google \ App Engine \ ORM and only include directories that you have
classes that you want enhanced. By default it does the entire project
so that includes a lot of needless files. (...)
Link :
original post # google-groups
Read the exception message again. Somewhere along the way Maven is generating a path that is too long for (some) Windows API to handle, try moving your workspace to a directory straight below C:\.
I just tried "skolima" reply and it worked for me. In Eclipse I clicked File->Switch Workspace.
Three things to note:
After I created the workspace in "C:\workspace" I had to update my Project->Properties > Java Build Path > Libraries > Add External JARs...
I'm using Windows 7.
I'm using "Eclipse Java EE IDE for Web Developers"
I hope this others.

How to get Scala Compiler Plugin to work in Scala IDE

Note: This is an exact repost of the same question on the Scala-IDE mailing list, where I got zero reply and gave up waiting after 5 days.
I'm writing a Scala Compiler Plugin. It's currently called
scalawrapper (but I might find a better name later). I have the
Typesafe Stack installed, and I put my plugin in it under:
C:\Program Files\typesafe-stack\misc\scala-devel\plugins
Now I can call scalac like this:
scalac -classpath ... -Xplugin-require:scalawrapper test\...
and it finds and uses my plugin automatically.
Unfortunately, I just can't get the Scala-IDE to use it. I always get
Missing required plugin: scalawrapper. In the "Project Properties
\Scala Compiler (Use Project Settings)\Advanced" tab, I have entered
scalawrapper in the Xplugin-require field, and that works, since I get
the error. But nothing I can type in Xpluginsdir seem to have any
effect.
I have tried the absolute path given above, have tried with forward
and backward slashes, have tried a temporary directory without spaces
in it, have tried relative to project directory, have tried relative
to workspace. It just will not use anything. I should also note that
is is not specific to my own plugin, as I tried to use the ScalaCL
plugin before in a previous version of the Scala-IDE, and failed for
the exact same reason.
I have just updated today (15.10.2011) and so should have the latest
version (it seems I can finally explicitly set the indentation to 4,
but maybe I just overlooked the setting in the past).
Can someone tell me what it actually expects, and what is uses as
default when I don't put anything in Xpluginsdir?
The Scala IDE uses the presentation compiler, not the compiler that you've installed. To use a plugin, with Scala IDE, you need to specify it in the preferences in Eclipse.
Try Windows->Preferences->Scala->Compiler. See the Advanced tab. The paths are relative to the workspace.
EDIT: When I say relative to the workspace, I mean the actual workspace directory under which the .metadata is stored ($workspace_loc). I have a project where project files including the source code is stored in one directory and the workspace is elsewhere, i.e the $project_loc (c:\code\project\source) is different from the $workspace_loc (c:\code\project\workspace). The directory that you specify in the compiler parameters is relative to the workspace ($workspace_loc).
To find out if you have a similar setup, go to the project and select Properties->Resource->Linked Resources.
I created a directory under $workspace_loc called plugin and placed the jar file in there. Under Windows->Preferences->Scala->Compiler Advanced tab I have
Xplugin = C:\code\project\workspace\plugin\xxx-0.0.1.jar
Xplugin-require = xxx
Please note that you can specify the plugin in the project properties as well, but it still uses $workspace_loc. The above configuration works for me.

Eclipse Extension Point for Updating the Classpath

Question
Given a Classpath Container I've written as a plugin/extension, how do I add it to the classpath, automatically?
Background
Ok so I'm an experienced Java Developer but extremely new to writing Eclipse Plugins. I've been googling, following tutorials and reading source code of other plugins for a couple days. I know exactly what I want to do but not exactly how to do it.
Right now, in Eclipse, when I click a resource and choose "Run as JUnit test" as in:
Behind the scenes, the m2eclipse plugin somehow generates a run configuration that contains the "Maven Dependencies" classpath container, like the following:
My best guess is that the "Maven Dependencies" classpath container is added through some extension point being used by the M2Eclipse plugin. Similarly, I want to add my classpath container, automatically, whenever a user runs a JUnit test--so it shows up under "User Entries." What extension point(s) can I use to make something like that happen? I've been looking at org.eclipse.jdt.core.classpathContainerInitializer but I'm not sure that's going to do what I need.
Ideal Result
Ideally, I'd like to write a plugin that takes every entry in the project's build path and adds it to the classpath of a run configuration (whenever a new launch configuration is created via: Run As > JUnit test). This should be the default behavior of Eclipse but it's not!
My next-best solution would be to simply add my custom classpath container to the run configuration's build path, automatically. At the end of the day, I just want one classpath for any java code our team runs/launches. This shouldn't be so hard!
Any advise on how to achieve any of this would be appreciated! Even basic pointers on where to look to understand how particular Extension Points are intended to be used (the basic JavaDocs APIs are terrible). Thanks,
gMale
Roostergx provides part of the answer (i.e., how to create the classpath container). The second part, as you admit, is how to add it automatically.
I would recommend using an extension point called org.eclipse.ui.startup. This allows you to contribute code that runs (pretty much) as early as possible when Eclipse starts up. On every startup, you can iterate through all projects and see if any existing projects require the classpath container that you created.
The article at http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/index.html provides an exellent description and source for a plugin that defines a project specific classpath container that includes all the jar files in a specified directory.

Eclipse classpath and NoClassDefFoundError

I'm going to try to give as much detail as possible here, pardon me if some is irrelevant.
I have two projects in eclipse. Project 1: com.myworkplace.parent, with code in the package of the same name. Project 2: com.myworkplace.child, with code in package of the same name (I moved my code to that package, from the default package, if that makes a difference). Both are located in my workspace folder and structured the way you'd expect them to be, as far as I can tell.
I've added child to the build path of parent in eclipse using Java Build Path -> Projects -> Add. Parent's .classpath file contains the entry:
<classpathentry combineaccessrules="false" kind="src" path="/com.myworkplace.child"/>
I add a reference to a com.myworkplace.child.Child class in parent, import it, compile it with no errors, run and get:
java.lang.NoClassDefFoundError: com/myworkplace/child/Child
What gives?
Edit: The parent application is an RCP app, maybe OSGI (I really don't know much about RCP and related stuff.) Some googling leads me to believe it might have something to do with this.
Since your application is an RCP app there is a difference between the eclipse classpath that is used while you are editing code and the OSGi classpath that is used at runtime. It sounds like you need to add the com.myworkplace.child plugin to the list of dependencies of the com.myworkplace.parent plugin.
Open either plugin.xml or META-INF/manifest.mf in the parent project. Eclipse should open the PDE plugin editor (a form based editor for the underlying config files). Click the Dependencies tab at the bottom and add your child plugin to the "Required Plug-ins" list on the left hand section of the form. Alternately you could add the com.myworkplace.child package to the "Imported Package" list on the right. The difference between the two is beyond the scope of this answer, but you can read about that in the eclipse docs now that you (hopefully) are moving in the right direction.
We found that even doing all the proper things in the eclipse rcp project, we were still getting such errors. The solution was to delete the application's workspace directory (by default it would store workspace settings under .eclipse, but we've tweaked our code to use another dir that is not shared with other eclipse stuff).
When we removed this dir after a rebuild, our app worked. Apparently it was storing the classpath somehow along with other settings, but we didn't investigate the exact details.
(NOTE: This applies only if you've called the IWorkbenchConfigurer.setSaveAndRestore method passing a boolean value of 'true' - which means that your application will save and restore various rcp settings after a shutdown of the application and subsequent relaunch.)
If your code is running in an application server, you need to configure the Classpath correctly for that application server.
To do that, find your Servers tab, double-click it, click Open Launch Configuration in the new tab that appears in the main editing area, click the Classpath tab and ensure the Classpath there is correct.