How can i open an Akka project using eclipse? - java

i am trying to create a simple hello-akka project using the typesafe activator. I have everything working and the project even runs in the typesafe tab. I clicked on create eclipse project, and some files are added to my directory but i cannot figure out how to open them and run the file in eclipse!
These are the files i currently have in the directory:
.sbtserver
project
src
target
gitignore
(GITIGNORE FILE?)
activator.bat and activator.jar
build.sbt
In another workspace i tried creating my own scala project, by adding akka-actor.jar to the libary but i get the following error :
Description Resource Path Location Type
missing or invalid dependency detected while loading class file 'ActorSystem.class'. Could not access term typesafe in package com, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.) A full rebuild may help if 'ActorSystem.class' was compiled against an incompatible version of com. tst Unknown Scala Problem
Any help or suggestions would be greatly appreciated!

There are quite a few dependencies you'll need to find and add if you're determined to make this work -- a scala-library, for example. It's better to find a way to integrate your build with your IDE if you can -- this will allow the IDE to find dependencies the same way the build does -- and in this case, the build system is SBT.
The easiest path forward may be to download ScalaIDE, which is a Scala specific package for Eclipse. This should come ready to go with support for SBT projects. Most Actor/Scala devs I know use IntelliJ or ScalaIDE.
Another option would be to use the SBT plugin for Eclipse, but in my experience it tends to be unreliable, changing with far less frequency than the IDE itself. If you install it and it doesn't look like it's working, you're probably right.
Finally, you can ditch SBT for Gradle or Maven and then use the Gradle or Maven plugins for Eclipse. If you have either of those in your shop already this is likely something you will need to do down the road, anyway. SBT is a good build system but nowhere near as feature rich as Gradle or ubiquitous as Maven.

Related

Steps to change IntelliJ GitHub project to download and build source code for dependencies

Using IntelliJ IDEA, it is often a straight-forward task to check out a project from GitHub and get it to build locally.
Once the base project is imported from GitHub, the IDE will download artifacts which will allow the main project to run. The dependencies can be examined by using File > Project Structure... > Libraries.
So the IDE downloads dependencies to allow running, but not to build from source. The IDE is able to decompile classes, but the IDE will not automatically download the source code for those dependency libraries so that the programmer can alter the code.
This question is about the steps required in the IDE and project configuration such that a selected dependency will be built locally, and thus allow the programmer to alter the code.
What I tried was to import the project on which the main project was dependent, as a separate project, then configure the main project to utilize the local project instead of the downloaded artifact. The first step, downloading the sub-project and getting it to compile, was completed successfully.
So I ended-up with two projects, the main one, and the one on which the main project depended. The task at hand, if this was the appropriate way to get this done, would be to open the main project and take some action to convince the main project to use the local build, rather than the downloaded runtime "jar".
First, I edited the POM.xml to comment out the dependency for the sub project. Checking File > Project Structure... > Libraries, I could see that it was gone, and the build now failed (as expected).
I went to File > Project Structure... > Libraries > + (plus sign) and poked around with New Module, and Import Module, but I was not able to convince the original project to use the locally available sub project. The result from various attempts was that code in the base project was not able to import from the sub project (unable to compile).
What are the specific steps to take in the IDE to get what was a runtime dependency "jar file" to instead to build locally, and use that instead?
Use a SNAPSHOT version for the dependency (you'll need to change this in both your project's pom.xml and the dependency's pom.xml, so if the current version is 2.0.0 change it to 2.0.0-SNAPSHOT)
Then you can edit the dependency's code and run mvn install in the dependency to provide the new version of the dependency to your project.
TLDR: there is no simple and straight-forward way of downloading a project's code and the code of its dependencies to rebuild it in one go as a complete chain.
Your project depends on several other artifacts. From the screenshot, we may assume that this is a maven project, at least we can be sure that there artifacts with compiled classes available for download, because this happends during build. You can view the compiled classes of your dependencies, because Intelli has the capability of decompressing jars and decompiling code, obviously, but the contents you are viewing is read-only.
Sidenote: Maven convention is to create 3 separate jars for each project. One with compiled classes, one with source files only and one with generated documentation. By default intellij may not download these, but you can force it (right-click on pom.xml -> maven -> Download sources and documentation). This will attach the actual source code instead of decompiled classes to your IDE, so it's much easier to understand the code - but still, there is no option to modify it - it's still read-only extract from some jar.
So what if you want to actually edit the source? You have 3 options, all with its own set of problems that need human intelligence to solve:
You extract the decompiled source from classes jar
You extract the attached source from sources jar
You check out git repository of the dependency
Now, beware of the downsides of each approach:
You can be sure that the decompiled source matches your project dependency 1:1. But decompiled code is not easy to read, missing comments, etc. Also, some projects may not ship their build scripts with the classes jar. Anything more complex than mvn clean install may turn out to be a blocker.
You can be reasonably sure the code matches your project dependency, but this actually is not a given. There is a chance of human error, causing the sources to actually not match the compiled classes (build from different revision or whatnot). Much depends on the quality of the project, the discipline put into the build process and care to avoid environment specific configuration that is not part of the source. The larger and older is the project, the less chances are you are able to recompile it successfully using only src jar.
A sane man's approach. You should have your build scripts, readmes, tutorials, etc. Except, of course, if we are talking some obscure company internal project with zero effort put in its maintenance. Surely, there are the same issues as before: not all projects are rebuilt easily on any environment. There may be steps upon steps required for your workstation to be configured as expected. Hopefully, self-respecting open-source java projects are easy to build, but again - not a given - not all project are open-source, not all are self-respecting.
Important note: When checking out the git repo of your dependency - you must also make sure that you are using correct revision. If the project is maintained with respect for git tags/branches naming convention - you are in luck. Not a given by any means.
All the above is enough to discourage any attempts to automatically decompose dependencies to compilable units by your IDE, and all the burden is put into you. So let's assume the best - our dependency is a simple, self-contained java application that is easily built using simple mvn clean install. You have it checked out in a separate project in your IDE. You identified correct git revision that matches version your project depends on.
Now let's apply your little change and test it. First thing you want to do is change pom.xml of your project to use a made up version of your dependency. It should be a -SNAPSHOT version for clarity and tidiness. You may of course build your modified dependency with real release version - but please be wary of how maven manages dependencies. If you install version 1.0 yourself - it stays in your local repo forever. You will forget about it, and will be using your fake 1.0 version when building all other dependent projects unless you manually locate and remove it from repo. So stick to 1.1-SNAPSHOT.
Now every time you need to apply a small fix to your dependency, execute mvn clean install in its repo, then make sure your actual project depends on the correct new SNAPSHOT version, execute your maven clean install and that's it.
Note that all this has very little to do with Intellij. You are not expected to modify any library paths, advanced project settings, or links to jars. Stick to modifying pom.xml and you are set.

How to resolve requirement: Import-Package:

The scope of this question applies after you have created an RCP app in eclipse following Vogella's tutorial linked below. This assumes your feature, product, and father project are created. In this state the feature is delegated the task of building, therefore all dependencies need to be resolved in the feature build.properties file.
This question addresses when the missing dependency needs to be installed, i.e. is downloaded manually because the missing dependency is not on the class path. The class path determines what plugins are available in the feature/included-plugins tab. The plugins listed in the feature/included tab can be added as plugins for dependencies to your plugin. This list gets appended to your feature.xml file which gets linked to your build.properties file! See Solution below.
Eclipse nomenclature interchanges the ideas of plugins=dependencies and treats them the same. We know this by the names of the tabs.
The intent of this question is aimed at using existing Eclipse capability to develop an RCP application that uses objects from a third party plugin to create a custom workflow.
This error is thrown because my RCP app third party plugin requires this dependency which was not included in Eclipse ICE nor the plugin itself.
The first thing I tried was to install the plugin directly from the Eclipse Marketplace.
The string org.apache.commons.beanutils returned nothing so I went to apache and downloaded the plugin manually.
I then researched how to install a plugin in Eclipse manually.
I've learned not to simply drop the plugin into the Eclipse/dropins folder, which does nothing.
I've learned that this advice is lacking probably due to age of post.
I've learned when Maven is configured correctly, all the dependencies can automatically be resolved.
https://www.eclipse.org/forums/index.php/t/813199/
This says plugin dependencies are resolved by looking at four files.
"The plug-in definition, the product file, the run configurations and the target definition."
The plug-in definition I'm not sure what that is other than the plugin.xml file. The product file has been configured to launch the third party plugin. I've learned the run-configuration has a list of plugins and the third party plugin is not listed there.
I've learned that the target definition should be created in the parent project of your product project.
Create a target definition by highlighting your father project->Right click-> new-> Other-> Target Definition. During creation select "Use workspace configuration." The path to your downloaded plugin was added to this Location.
After the Target is created, Navigate to the content tab and select Manage Using: Features
This reduces the number of possible dependencies to only the ones needed to run.
You should now see the dependency checked in the list.
Creating the target resolved the other twenty or so dependency errors but the one under the title still throws an error.
I've learned that the product file is the file that calls the third party plugin in runtime.
The RCP app launches, but I cannot import the third party plugin in the bound classes created using this tutorial, to be used to obtain objects programmatically.
http://www.vogella.com/tutorials/EclipseRCP/article.html
I have a shell of a program running and just need to implement the classes for each window with the objects I can get from a third party plugin import.
Thanks,
(Solution)
Thanks Brian for resetting my thinking which led me to learn about Eclipse a little more to figure this out.
The main problem is an external .jar is identified as the missing Import-Package. Mine was org.apache.commons.beanutils. You must go to the parent website and download the library. In this case apache's website. There is probably a better way to do this by repo. I'm hoping I can export the product with all the required dependencies :p
I may be able to skip a step or two here, but these were my working steps.
Get .jar into Eclipse parent project. Right click the parent and select New->Folder->Name it Lib->Finish. Right click Lib->Import->File System->Navigate to .jar. Highlight the included .jars->Right Click->Build Path->Add to the Build Path.
Add the missing .jar to your Ant class path. Ant is used to build PDE apps using OSGi. See the Eclipse Help for an explanation. This will allow your missing jar to become visable in the feature project included-plugins tab.
Window->Preferences->Ant->Runtime->ClassPath Tab->Add jar->Navigate to missing jar
Create a target definition as described above in your parent project and add your missing .jar to the target and set your target active.
If target exists, In Locations widget window->Click Add->Directory->Navigate to missing .jar.->Next-> Verify plugins are recognized in window->Finish. Click Set as Target Platform in upper right corner.
Open feature.xml in your feature child project. ->Click Add->Navigate to your added plugin->Click Ok
Save All - Launch product
Now onto the next dependency!
Sounds like you're confusing an Eclipse plugin with a jar dependency for your project. it sounds like your project needs a jar (the beanutils jar from Apache) . Depending on if your project uses Maven or ant (or something else) the way to add it to your project varies. Try googling something like "adding a jar in eclipse for a X build" where X is the tool used for your build (ant, maven, etc). No matter what you use, the end goal will be for that jar to show up the java Build path->Libraries for your project in Eclipse.
it seems to me that u need a better understanding of how dependencies are managed in OSGI/eclipse, therefore i concur with BrianPipa.
beware: that subject is quite large and not easy to understand and is way too large to be explained here. but be not afraid, google is ur friend:
a few pointers on research topics:
the relation ship of bundle/plugin and jars
how is code contained in a plugin exported (aka make visible) to other plugins so they can use it AND what needs to be done so that the using plugin (ie. declare that usage-dependency)?
how are feature related to plugins?
how are products related to plugins and features?
what is a target platform ?
and how do i define it and what does it need to include ?
how do i set it ?

Scala eclipse-plugin Project unmanaged dependencies of referenced projects not on classpath after upgrade from 2.9 to 2.10

I recently tried to upgrade from Scala 2.9 to 2.10 and ran into the following difficulties:
I have two scala eclipse-plugin projects. The first one has some unmanaged libraries on it's build path. This project compiles and runs fine.
The second project depends upon the first project and some Java project configured via eclipse-plugin dependencies.
Here I get four not very helpful compile errors. Three times the following
SBT builder crashed while compiling. The error message is 'bad symbolic reference. A signature in XSBInterRunner.class refers to term interprolog in value com.declarativa which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling XSBInterRunner.class.'. Check Error Log for details. de.wwu.sdpn.wala Unknown Scala Problem
Plus another dumping the class path which actually does not contain the corresponding library.
If I manually add the missing libraries to the second project the first project isn't found anymore. Even though it was on the dumped class path previously.
When compiling the projects from the command line via SBT using a more or less equivalent setup everything works fine.
I've also tried to reconfigure the dependencies not to use the eclipse-plugin mechanism for dependency management but directly added the other project to the build path but this also didn't help. Reimporting the projects to a clean workspace also didn't help.
The problem exists both with the 3.0.1 and the nightly version of the scala-ide plugin on Eclipse 4.2 and 4.3.
Any idea how to resolve this issue? Is there any way to find out why the libraries are missing from the class path?
From the description, it looks like the unmanaged library is not exported from the first project. Verify that in project properties > Java Build Path > Order and Export, the checkbox next to the library is selected. It is needed to make jars visible to other projects.

Create Eclipse java project with a java programm

I would like to generate Eclipse Java Project with my Java program. When I click a button: it will generate an eclipse project with the parameters I specified (source path, library, ...)
My questions are:
is there a way to do that ? and how ? (api).
it is possible to generate Net-beans project too ?
Best regards,
Florent
Maven enables this and many more things around creating, bulding, testing and developing Java projects.
Create a Java project from command line. Then, using Maven create NetBeans, Eclipse or IntelliJ IDEA specific project files. Or even easier, just import already created Maven project directly from these IDEs.
Create Java Project in Eclipse first. Then look into directory created. You should find there two files: .project and .classpath. These are the files you should create in your app to get what you want.
Also for eclipse available M2Eclipse plugin to provide some Maven feature from Eclipse IDE.
http://m2eclipse.sonatype.org/
While Maven is the way to go in the long term, the best way to start a project in Eclipse is:
Hit Ctrl+N and choose Java project
Fill in the project name fields
Copy your files from wherever they are to the newly created project (ensuring to preserve package hierarchy)
Refresh project from File menu
Create a Run / Debug profile to run your app.
It should be fairly simple to get up and running this way.
The reason people recommend Maven is because Eclipse is an IDE. It's great for development but its no good for resolving external dependencies or for command line / automated builds. Maven is an IDE neutral way of building and becomes essential the more dependencies a project pulls in.
Unfortunately Eclipse integration with Maven is pretty clumsy and can be summarized with these very broad steps:
Install Eclipse Helios
Install m2eclipse from the Help | Eclipse Marketplace
Mess around with eclipse.ini to make Eclipse start from a JDK.
Configure m2eclipse to use any existing Maven local repository
Hit Ctrl+N and create a new Maven project and skip archetype selection
Copy all the source files from the old project into the new ensuring to use Maven's conventions for file locations. (e.g. source goes in src/main/java)
Create a Run / Debug maven target to clean / install the app
I say broad steps because there are a lot of gotchas. For example if the source is Java 5+ you might have to tweak the pom to set the compiler level. Best to get Eclipse working and then worry about Maven.
Netbeans has vastly better out of the box support for Maven although IMO Eclipse is still the better IDE for other reasons.

Packaging and deploying a Jython program from Eclipse

So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. I've gotten all my Python scripts working and I'm successfully including a couple of JAR files and the class directory of another Java project as external dependencies. Everything seems to run fine through the Eclipse IDE.
Now I need to package everything up and deploy it. From what I can gather, the best way to do this would be to package everything up in a JAR file. The Jython documentation suggests starting out with the jython.jar file and adding to it. OK. So I modify my main python module and start adding all my python source to the JAR.
It executes but of course can't find all the external dependencies.
How is one supposed to add the external JAR files so that they are correctly seen by the Jython interpreter? How is one supposed to manage more complex dependencies in a setup like this?
Is there a plugin for Eclipse or maybe something like Ant or Maven that can handle all of these steps for me with the push of a button?
I can't be the first person that has needed to deploy Jython code with complex dependencies can I?
I've made some headway on getting this all working so I thought I would put some notes here in case they help anyone else out. I'd still like to hear from others on their experiences trying to put together something like this.
It turns out that Eclipse as of 3.5 has a project export option for Java -> Runnable JAR File. If you use this option, you can point to a Java main class in the export wizard. You also have the option to have it repackage all the JARs that you are dependent on in your new JAR file. Make sure to check the box to save the export as an ANT build so that you can repeat the process quickly. NOTE that the first time you do this through the interface, it may fail, but it will still have created a JAR file.
Now here's where it gets strange. To track all the dependencies, I am still using a mostly incomplete Maven build in my project. I create the Maven .POM file. And I told Maven what my external JAR dependency was. I then told Maven to do a dependency update for me. It pulled everything into my Maven repository as expected.
Now when I do my ANT build, it appears that it is getting its list of JARs to include in the final build from Maven. I'm not really sure if it is supposed to work that way. I'm also not 100% sure that it is working. I guess I'll find out when I have to add another external JAR to the project.
Anyways, if you follow this question you'll see that you can take the latest builds of Jython and pull the org.python.util.JarRunner.java file out and use it in your own project. This is you Java.main class that you will need to point your ANT build at. From there, convert your main Python/Jython script to be the run script that was talked about in that question.
Next, build up another copy of the Jython JAR file in your Jython directory. This one should have the /Lib directory pulled into the JAR. Save that off and then point your Eclipse IDE Jave Build option for your PyDev project at that JAR as an external dependency. Your JarRunner will now work and execute the run.py file under Jython.
If all that works, you should then be able to rerun the ANT exported build from earlier and you will end up with a single JAR file that you can execute on the command line as:
java -jar {yourjar} args
And distribute to your customers without any additional dependencies.
If that all seems a little bit convoluted, it is. If anyone has a better way of setting this all up using Eclipse, please let me know.
Make your life easier and just use Maven and the mavenjython compile plugin.
See my answer of this question: Using Jython with Maven
You get full automation of the build and deploy process, and the result is a jar that includes jython and all other dependencies.

Categories