Eclipse PDE/OSGi: Reflections Library not finding packages - eclipse

The org.reflections library does not function correctly when it's used inside an Eclipse Plugin project.
For instance, the following code should return all classes of a given subtype in a given package:
Reflections reflections = new Reflections("my.package");
Set<Class<? extends Subtype>> classes = reflections.getSubTypesOf(Subtype.class);
When running the project as a Plugin, classes will be empty. Inserting a main() and running it as a normal Java application will correctly return the expected classes.
I've tried to:
Include the Reflections library as a normal third-party jar dependency
Include the Reflections library as an OSGi bundle (http://stackoverflow.com/questions/8339845/reflections-library-not-working-when-used-in-an-eclipse-plug-in)
Edit: current process (based on stackoverflow answer above):
1) New Plugin-Project (OSGIReflections called) based on external JARs (Reflections and Javassist)
2) In my actual Plugin-project (X) I add a dependency on OSGIReflections in Dependencies -> Required Plug-ins
2.a) If I run the project as normal java app: Reflections is working
2.b) If I run the project as plugin project: Reflections is not working
3) Create the BundleUrlType class
4) How do I activate this BundleUrlType? In my plugin Activator I call the createReflections(context.getBundle()) function but I do not have a .data file. How do I generate that?

Related

How to fix dependency injection when upgrading play framework from 2.5.x to 2.6.x Scala

I am trying to upgrade from play 2.5.x to 2.6.3. (Because 2.5.x doesn't support multipart post in WS. import play.api.libs.ws.DefaultBodyWritables._ throws Exceptions. The code example in the official document doesn't work. The compiler needs the Body Writables which is not provided until 2.6.x)
So I changed the plugin.sbt version to 2.6.3 and upgraded sbt to 0.13.15. And edit the build.sbt file to add guice and json. The project compiles fine. But when I started with sbt run, and visit http://localhost:9000, it throws a bunch of Exception related to a jar file I have in the local lib/ directory. The same code worked just fine with 2.5.x.
Here's the exception:
1) Error injecting constructor, java.lang.NoClassDefFoundError: com/google/common/util/concurrent/FutureFallback
at db.ConcreteGGDB.(ConcreteGGDB.scala:24)
at Module.configure(Module.scala:29) (via modules: com.google.inject.util.Modules$OverrideModule -> Module)
while locating db.ConcreteGGDB
Any idea if this is related to the local jar is not compatible with 2.6.x? or I need to change some code to do dependency injection other than specify in the Module.scala file? Thanks.
Why am I getting a NoClassDefFoundError in Java?
Error injecting constructor, java.lang.NoClassDefFoundError: com/twitter/finagle/http/Method$Get$
NoClassDefFound means that there's a class that your code needs, but
it can't find it. This typically happens when your project
transitively depends on more than one version of a library. For
example, imagine that you're building project A, which depends on lib
X, and project B, which also depends on lib X. However, project B was
built against an older version of lib X, which used to have a class,
but which it no longer exports.
A => B => X (version 1)
A => X (version 2)
Then when it runs, A makes a call into B, which tries to make a call
into X, but because the project now uses the newer version instead of
the older version, it can't find the class it needs.
I would encourage you to use sbt-dependency-graph to see which
versions of [library name] you're depending on transitively, and ensure that
every library you use uses the same version of [library name].
Looks like an issue with the local jar.

build paths eclipse java j2ee

I have imported a project (I am very new at this) and I get the following errors:
Project cannot be built until build path errors are resolved
Project FST is missing required library: 'C:program Files/Apache Group/Tomcat 4.1/common/lib/servlet.jar'
Project FST is missing required library: 'C:program Files/Apache Group/Tomcat 4.1/common/lib/struts.jar'
The project cannot be built until build path errors are resolved
Unbound classpath variable: 'TOMCAT_HOME/common/lib/jasper-runtime.jar' in project
Unbound classpath variable: 'TOMCAT_HOME' in project FST
I create a variable called TOMCAT_HOME and give it the proper directory ,but Also, we should change the project classpath to use TOMCAT_HOME rather than the absolute path.
i dont know how to do it (change the project classpath and the absolute path)
thanks !
To answer somewhat indirectly, if you configure your project build with something like Maven or Gradle, so that you can successfully build the project using the corresponding command-line tool, then it should be quite straightforward to import the project into eclipse using the Maven or Gradle eclipse plugin. I think doing so will be worth whatever trouble it causes you in the short run--just take care to make your project structure conform to the usual project structure that Maven expects or you'll be asking for trouble (it should be no problem to do so for greenfield work).

Gradle project.sourceSets.main.runtimeClasspath always blank

I'm writing a Gradle plugin to generate Java code from WSDL. Problem is, my task does not find the Java class I'm trying to execute and blows up at runtime with a ClassNotFoundException even though the necessary jar is listed as a compile dependency. I'm using project.sourceSets.main.runtimeClasspath but have tried compileClasspath, adding a build script section to the build file, using configurations.runtime, all to no avail. Note that my project has no Java src code, just Groovy.
Any ideas? The task, a unit test and the build file can be found here:
https://gist.github.com/abhijitsarkar/8432347
c.f.: cross posted on the Gradle forum
It turns out that because my plugin uses project.sourceSets.main.runtimeClasspath, the client needs to declare the dependencies with runtime scope. It is not enough to have the dependencies declared in the plugin project only.

scala & intellij : difficulties to create a runnnable jar

I can't launch a scala jar; when I launch it I get the error "Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/immutable/List" which seems to mean the scala library is not loaded...
this is a screenshot showing a lot of informations on the artifact window.
here is the manifest:
Manifest-Version: 1.0
Class-Path: libs/scala-library-2.10.0.jar libs/commons-logging-1.1.1.j
ar libs/jcip-annotations-1.0.jar libs/jwnl-1.4_rc3.jar libs/laf-plugi
n-7.2.1.jar libs/laf-widget-7.2.1.jar libs/miglayout-core-4.2.jar lib
s/miglayout-swing-4.2.jar libs/scala-actors.jar libs/scala-library.ja
r libs/scala-swing.jar libs/slf4j-api-1.6.4.jar libs/slick_2.10-1.0.0
.jar libs/sqlite-jdbc-3.7.2.jar libs/substance-7.2.1.jar libs/trident
-7.2.1-swing.jar
Main-Class: Fenetre
and when I enter "java xf myJar.jar", there are extracted files in the directory:
- .class files
- in the libs folder, there are the libraries INCLUDING scala-library.jar & scala-library-2.10.0.jar(I specified only one of these two files in the manifest to avoid conflicts)
can you help me?
I'm new to Scala and don't know what the problem is however I've been compiling "fat jars" which include all the required libs.
I've been using https://github.com/sbt/sbt-assembly to do this successfully.
Despite what your manifest is telling you, when you run the application you either do not have the scala-library included in your class path or there's some confusion when you attempt to import List. Scala should automatically import the immutable collection classes in your project with the root Predef implementation.
Predef provides type aliases for types which are commonly used, such as the immutable collection types scala.collection.immutable.Map, scala.collection.immutable.Set, and the scala.collection.immutable.List constructors (scala.collection.immutable.:: and scala.collection.immutable.Nil). The types Pair (a scala.Tuple2) and Triple (a scala.Tuple3), with simple constructors, are also provided.
Predef in core Scaladocs
Try printing the classpath from within your app to confirm.
Although not pertinent to your question, I would recommend using SBT for dependency management now that IntelliJ IDEA 13 has full SBT integration support. Your collaborators not using IntelliJ will also be happier because SBT gives them more options for build technologies, editors, and other tooling when working on the project.

Unable to generate metamodel definitions using DataNucleus JPACriteriaProcessor from Eclipse

I'm trying to generate the metamodel definitions in Eclipse as documented on:
http://www.datanucleus.org/products/accessplatform/jpa/jpql_criteria.html
My project compiler level is set to 1.6 and the mentioned datanucleus jars are added to the factory path.
When the project builds I get the following error:
Errors occurred during the build.
Errors running builder 'Java Builder' on project 'X'.
Could not initialize class org.datanucleus.jpa.query.JPACriteriaProcessor
When using mvn compile the metamodel definitions are generated successfully, so it's probably related to Eclipse annnotation processing.
I'm using latest Spring Tool Suite 3.1.0.RELEASE based on Eclipse 4.2.1
Not put persistence-api.jar (or equivalent, such as Geronimo specs JPA2) in the Factory Path? Either way one of the deps is missing