Import a Eclipse project using Java Code - java

I have gone through the previous thread on the same topic
After reading that i tried to use the same code. I am very new to Eclipse plugin development. I tried to see the given example links but couldn't find the correct thread.
I have a similar requirement. I tried to develop a plugin following this link
Should i compulsory develop a plugin or is there any way where i can run it from java main method.
Thanks,
Vamsi

Basically, you have to write an Eclipse plug-in, as the suggested code re-uses existing features only available in an Eclipse plug-in environment.
For the referenced code to work, you have to maintain a plug-in with the dependencies org.eclipse.core.resources plug-in, and you also have to provide some functionality to execute this code (e.g. a platform command, as in another the mentioned vogella.de tutorial.
In theory, it might be possible to do it in plain Java code, but in that case it would make more sense to do it by directly editing the metadata files - and that is a way I do not recommend.

Related

Automated unit testing for java as soon as code changes

Are there any tools/libraries like Guard (for Ruby on Rails) for Java which listen to file system changes i.e. changes to the code files in the project and automatically run unit tests associated with that class or the entire project.
Looks like you need something like Jenkins, running locally + FSTrigger plugin.
But if you need to monitor file system changes from your app (Guard is general-purpose tool), there is discussions on Stackoverflow about it:
Is there a sophisticated file system monitor for Java which is freeware or open source?
File changed listener in Java
How to detect filesystem has changed in java
The interesting thing is that yes, Guard.rb does support java thanks to the guard-java gem. Best thing of all is that this does support maven, ant, or what ever your build system is. This allows for setting up jenkins and cucumber then having guard run your tests as you edit the features/source code.
Add the following to your project's Gemfile:
gem 'guard-java'
Then issue bundler install && guard init java
The rest can be read at https://github.com/infospace/guard-java
I don't know if you are still up for an answer but I wrote a small tool, inspired from Guard, that could do what you want:
https://github.com/athieriot/JTaches
It uses the Watcher API available in Java7
Hope it helps

java.lang.NoClassDefFoundError in android

I am new to Android development. I'm working on an project which involves using stubs for web services. When I try to use it, I get the following error:
I've been stuck here for a week, so some help would be highly appreciated.
It seems that there is some packaging or deployment issues with the included libraries that you use in you project. This error is thrown when the Java Virtual Machine or a ClassLoader instace try to load the definition of the a class but cannot find it anywhere. In most cases, this occurs when something is messed up in your project configurations but i cannot tell what from the information provided. A solution would be to configure your project from the scratch since most of the times this is easier than finding what causes the problem. Also in case you had an older version of ADT (<17) the answer of this SO question might be usefull. Finally, if you are importing any javax libararies(or libraries that have javax components in them), this maybe the source of your problem since Adroid does not support the javax library.

Methods to see result fo a code change faster

This question came to me when developing using Eclipse.
I use JBoss Application Server and use hot code replacement. But this option requires that the 'build automatically' option to be enabled. This makes Eclipse build the workspace automatically (periodically or when a file is saved?) and for a large code base this takes too much time and processing which makes the machine freeze for a while. Also sometimes an error message is shown saying that hot code replacement failed.
The question that I have is: is there a better way to see the result of a code change?
Currently I have the following two suggestions:
Have unit tests - this will allow to run a single test and see the result of a code change. ( But for a JavaEE application that uses EJBs is it easy to setup unit tests?)
Use OSGi - which allows to add jars to the running system without bringing down the JVM.
Any ideas on above suggestions or any other suggestion or a framework that allows to do this is welcome.
Did you take a look at http://zeroturnaround.com/jrebel/?
I tell you how I work. I hope it is useful. First of all, I disable "Build Automatically". Maybe it is better if you do a simple ANT script to compile and see errors/exceptions. Also, I make jar file with the same script. Afterwards, I use OSGi to check the application. Yo do not need to stop server, only you need to change versions in deployed bundles. Intead of JBoss Server I use Equinox which includes Jetty Web Server.
May you have a nice day!
With JRebel, you wouldn't have to build your project (skip the build totally). Plus, only the changed resources will be reloaded so the update happens instantly. Plus, session is preserved so you do not have re-login to the application after the update was performed.
Even though the question I asked was quite specific to Java, I thought that mentioning using an interpreted programming language that avoids the compilation step is anther way of seeing result of a code change faster.

Java: separating JAR versions

I'm developing a Java plugin for an existing Java program. The existing program uses a specific version of eclipse.uml2.* and my plugin does too. Unfortunately I need a newer version for my plugin.
In order to run the plugin, I need to export it into a Jar file (with all jars packed). Then the program executes it. But somehow the new eclipse.uml2.* seem to interfere with the program -> it crashes.
Is there a way to "separate" both versions of the jar files?
An approach will be to use a custom class loader in your application. This can very easily introduce bugs that are difficult to trace, so take care.
http://www.devx.com/Java/Article/31614/1954
This is the exact problem OSGi tries to solve. Would it be feasible to rework the Java app to another plugin platform?
This will be difficult. You conceivably try to use class loader tricks to allow both versions of the eclipse.uml.* classes to be loaded in the same JVM. But as far as the JVM would be concerned they would be different sets of classes, and your plugin and the base java app wouldn't be able to exchange instances.
It is probably simpler (and less risky ... in terms of likelihood of success) to rebuild (and if necessary modify) either the base program or your plugin so that they both work with the same version of the eclipse.uml2.* classes.

Best ways to manage generated artifacts for web service/xml bindings in a java webapp/client?

I'm working on a couple of web services that use JAXB bindings for the messages (in JAX-WS or spring-ws). When using these bindings there's always some code that is automatically generated from the WSDL to bind the message objects. I'm struggling to figure out the best way I can make this work so that it's easy to work with, hard to break and integrates nicely with IDEs (mostly using eclipse).
I think there are a couple of ways to go about this. The three main options I see right now are:
Generate code, keep the source artifacts and check them into the repository. Pros: integrates easily with IDEs (source highlighting etc), works within the build system. Cons: generated code changes each time you regenerate it, possibly creating noisy commits. It's also redundant since the WSDL file is already checked in, usually.
Generate code as part of the build process. Don't keep source artifacts or only keep them in output directories. Pros: fixes all the cons from the previous one. Cons: harder to integrate with IDE, though maybe this build step can be run automatically? I currently use this on one of my projects but the first time I checkout the project it appears broken, which is a minor nuisance.
Keep generated bindings in separate libraries (jars) included with maven or manually updated jars, depending on your build process. I got the idea from a thread on java.net. This seems more stable and uses explicit versioning but seems a bit heavyweight.
Which one of these options would you implement and how? We're currently using maven and eclipse, so any ideas in that regard would be great. I think this problem generalises to most other build systems and IDE combinations though, even other languages perhaps.
I went for option 3. If you already host your own repository (and optionally CI), it's not that heavyweight. All it takes is a simple POM. It's even possible to include some utility/wrapper/builder classes (that often make life easier with generated classes) and use them in several projects.
I'd go for option 2 and generate code in the "standard" ${project.build.directory}/generated-sources/<toolname> location as part of the build process. Using generated sources is well supported by m2eclipse (use Maven > Update Project Configuration once sources have been generated) and, if I remember well, by the maven eclipse plugin as well (i.e. the folder will be added to the Java Build Path). Actually, I think NetBeans also handle this fine. Not sure for Idea.
For the generation itself, you may need the maven-jaxb2-plugin if I understood correctly.

Categories