Scala IDE for .NET Developers - java

I write C# commerically and I am using Scala IDE ( Eclipse) at home. I want to be able to structure my project so I have a play component (.NET equivalent Assembly / VS Project) and another component which is the Core (Model, Services etc)
How do I do this in the Java / Scala world with Jars etc. How do I structure this in eclipse to get these results?
Cheers.

It depends if you use maven. If you do, you would create a project for the play component which has a dependency on the core component, which is another maven project.
If you don't wanna learn maven because you want only a fast solution, create two separate java projects and in the project properties of the play component go to the "build path">projects tab and add the other project (core) there, this will also create a workspace dependency

If it is a play project, you can just generate the eclipse project by using 'eclipse' command in the play console, and just import the project.

From the Scala IDE point of view, there are 2 possibilities:
the sbt build contains 2 projects, the core one and the play one. Using eclipse from the sbt prompt will generate the correct Eclipse configuration file, and the 2 projects will be linked when imported in the workspace.
there are 2 sbt builds, each containing one project. The eclipse sbt command will generate independent project configurations. After importing the projects in the workspace, the Java build path (in the project properties) will have to be tweaked to make one project depend on the other. (quick tip: make sure to select the dependencies you need in the Order and Export tab).
If you set it up with 2 sbt builds, you will likely need to publish the core locally, and add it as a dependency in the play build.
I will let others chime in about configuring multi-projects in one sbt build.

Related

How to import package in a java project from another java project in IntelliJ IDEA?

I m working in a project A (java)in IntelliJ IDEA , now I need functionality from another project B(java) .I want to import desired packages from project B into Project A. How can I achieve it?
I would recommend you use a build system like Gradle or Maven. That way, anyone who is able to check out your projects from version control will be able to build your projects, even if they choose not to use IntelliJ. (While either Gradle or Maven would work, I do not recommend using the Ant build system, because it does not support dependencies out of the box.)
You can either create a multi-module Gradle build, which is the easiest, or you can even publish a jar to a repository like Artifactory and then depend on a particular version of that jar in your second module.

Importing multiple git repositories into one project in Intellij

I'm moving over from eclipse to Intellij, and I hit a snag on setting up my project
I have 4 projects on github that, in eclipse, all live in one workspace. They are API, Server, Client, and Basic Plugin, and they each have a Maven pom.
What I want to do is set up Intellij's project structure similar to Eclipse's workspace, where all 4 of those projects are side by side in the explorer, but it's not letting me import more than one maven project as a module (I import the first fine, but the rest silently fail), and importing directly from github creates a whole new project for each repository, which is not ideal.
I tried to import a in my eclipse workspace, but it all broke (Object and Math were not found), and all the java environment setting were wrong.
Any ideas? I'm fairly new with Intellij and I really like it, but I don't want to switch over from eclipse if I can't get my workflow right.
First of all, Intellij IDEA uses different naming than Eclipse, you can learn the details here: http://www.jetbrains.com/idea/documentation/migration_faq.html. In short, Eclipse's Workspace is called Project in IDEA, and Eclipse's Project is Module in IDEA. In your case, you want to have multiple Maven-based modules in one Project. You can do it by creating a Project with one Module and then adding the rest of Modules (File->Add Module->Import Module from external model->Maven etc.).
As for the multiple Git repositories, you can configure that using this help page: http://www.jetbrains.com/idea/webhelp/git-branches-in-multirooted-projects.html
In your case, have a look at the 'Asynchronous branch control' section). It's really straightforward, I have just done it myself for the first time by following these instructions.
Good luck.
UPDATE: The above link now gives 404, so here are the most up-to-date ones that may be of help:
https://www.jetbrains.com/help/idea/2017.1/git-branches-in-multirooted-projects.html
https://www.jetbrains.com/help/idea/using-git-integration.html
IntelliJ opens one project at time, but this project can have multiple modules ( say, maven reactor ). So modules are kind of [related] workspace projects in eclipse. You also can open several independent projects in different windows.
In case you have working maven reactor build, you can just open topmost pom as project and everything will be set up. ( treat maven reactor as your workspace )

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.

How to make a project "repository/team" ready

I have been working solo on a project for some time, and now, new developers are likely to join the project for various reasons.
I, of course, use a version control software but I am afraid importing my project into Eclipse and making it run might prove a little difficult for new comers, and I want to make it as clean as possible.
When I first took over the project, it took me almost two days to have the project built and run it, I documented every step and fixed the most obvious errors, but not all, and I want the project to run as it is when imported.
The project is a mix of java projects for the backend, a j2ee project for the server and a flex project for the client.
The IDE is going to be Eclipse
The version control software is Perforce
Here are some of the specific problems I have right now, should I fix them, and how ?
Eclipse environment variables are used for libs, all the libs are in a folder in the j2ee project but are used by all the java projects (they have to be set in each IDE the project is imported into)
Runtime JRE is specified in .classpath for each project, so each projects property must be edited when trying to build the project in another environment
Apache server is specified in j2ee project property
To avoid exporting the jars of all the java projects into the j2ee project each time I modify the code, there are linked folders in the j2ee projects, linked to each java project bin folders
For (4) I will probably have to use maven, but is it possible to fix problem (1) (2) and (3) without using maven ?
The alternative is to have a one page set up instruction document
Also do you have any other general or specific advices as to how organize this whole mess.
Thank you
Dependency management is a must - use Maven. If you can't use maven, because you are already using ant, go with Ivy.
Make the project buildable with one click - be int ant build all or mvn package. Maven provides integration with the IDE (via the plugin).
Don't reply on IDE metadata. like .project and .classpath. You can still commit them to ease Eclipse users though, but don't restrict the IDE.
Provide build-on-save. Either using Eclipse WTP, or using the FilSync plugin (it sounds like a hack, but is pretty cool)
Use build profiles (maven provides them automatically) - to create different builds for different environments
It's not always possible to configure everything in your maven (or ant/ivy) scripts. For any additional actions, like installing app server - document then in a single file in the root of your project, describing step by step what should be installed, with what config options, etc. Thus the developers have only one place to look at and follow. The document can (and better) be plain .txt
A sidenote: use Continous Integration - download Hudson or TeamCity and configure it to build a project
From my very recent experience - we had a project we've been working on for 6 months. A colleague of mine had to re-import the project on a new machine. It took him 20 minutes. The project is configured with Maven.

Convert Existing Eclipse Project to Maven Project

For a project at work, we're considering using the Maven plugin for Eclipse to automate our builds. Right now the procedure is far more complicated than it ought to be, and we're hoping that Maven will simplify things to a one-click build.
My question is, is there a wizard or automatic importer for converting an existing Eclipse Java project to a Maven project, using the Maven plugin?
Or should I create a new Maven project and manually copy over all source files, libs, etc.
Start from m2e 0.13.0 (if not earlier than), you can convert a Java project to Maven project from the context menu. Here is how:
Right click the Java project to pop up the context menu
Select Configure > Convert to Maven Project
Here is the detailed steps with screen shots.
If you just want to create a default POM and enable m2eclipse features: so I'm assuming you do not currently have an alternative automated build setup you're trying to import, and I'm assuming you're talking about the m2eclipse plugin.
The m2eclipse plugin provides a right-click option on a project to add this default pom.xml:
Newer M2E versions
Right click on Project -> submenu Configure -> Convert to Maven Project
Older M2E versions
Right click on Project -> submenu Maven -> Enable Dependency Management.
That'll do the necessary to enable the plugin for that project.
To answer 'is there an automatic importer or wizard?': not that I know of. Using the option above will allow you to enable the m2eclipse plugin for your existing project avoiding the manual copying. You will still need to actually set up the dependencies and other stuff you need to build yourself.
I was having the same issue and wanted to Mavenise entire eclipse workspace containing around 60 Eclipse projects. Doing so manually required a lot of time and alternate options were not that viable. To solve the issue I finally created a project called eclipse-to-maven on github. As eclipse doesn't have all necessary information about the dependencies, it does the following:
Based on <classpathentry/> XML elements in .classpath file, it creates the dependencies on another project, identifies the library jar file and based on its name (for instance jakarta-oro-2.0.8.jar) identifies its version. Currently artifactId and groupId are same as I couldn't find something which could return me the Maven groupId of the dependency based on artifactId. Though this is not a perfect solution it provides a good ground to speed up Mavenisation.
It moves all source folders according to Maven convention (like src/main/java)
As Eclipse projects having names with spaces are difficult to deal on Linux/Unix environment, it renames them as well with names without spaces.
Resultant pom.xml files contain the dependencies and basic pom structure. You have to add required Maven plugins manually.
Right click on the Project name > Configure > Convert to Maven Project > click finish. Here you will add some dependencies to download and add your expected jar file.
This will create an auto-generated pom.xml file. Open that file in xml format in your eclipse editor. After build tag (</build>) add your dependencies which you can copy from maven website and add them there. Now you are good to go. These dependencies will automatically add your required jar files.
Chengdong's answer is correct, you should use Configure>Convert to Maven Project. However, I must add the conversion process has been greatly improved since m2e 0.13.0 : m2e 1.1+ and m2e-wtp 0.16.0+ can now convert the existing eclipse settings into maven plugin configuration .
As for the dependency conversion matter, you can try the JBoss Tools (JBT) 4.0 Maven integration feature, which contains an experimental conversion wizard, plugged into m2e's conversion process : http://docs.jboss.org/tools/whatsnew/maven/maven-news-4.0.0.Beta1.html.
It does not pretend to be the ultimate solution (nothing can), be it should greatly help bootstrap your Maven conversion process.
Also, FYI, here are some ideas to enhance m2e's conversion process, refactoring to use a Maven layout will most probably be implemented in the future.
JBT 4.0 (requires Eclipse JavaEE Juno) can be installed from http://download.jboss.org/jbosstools/updates/stable/juno/ or from the Eclipse Marketplace
It's necessary because, more or less, when we import a project from git, it's not a maven project, so the maven dependencies are not in the build path.
Here's what I have done to turn a general project to a maven project.
general project-->java project
right click the project, properties->project facets, click "java".
This step will turn a general project into java project.
java project --> maven project
right click project, configure-->convert to maven project
At this moment, maven dependencies lib are still not in the build path.
project properties, build path, add library, add maven dependencies lib
And wait a few seconds, when the dependencies are loaded, the project is ready!
There is a command line program to convert any Java project into a SBT/Maven project.
It resolves all jars and tries to figure out the correct version based on SHA checksum, classpath or filename. Then it tries to compile the sources until it finds a working configuration. Custom tasks to execute per dependency configuration can be given too.
UniversalResolver 1.0
Usage: UniversalResolver [options]
-s <srcpath1>,<srcpath2>... | --srcPaths <srcpath1>,<srcpath2>...
required src paths to include
-j <jar1>,<jar2>... | --jars <jar1>,<jar2>...
required jars/jar paths to include
-t /path/To/Dir | --testDirectory /path/To/Dir
required directory where test configurations will be stored
-a <task1>,<task2>... | --sbt-tasks <task1>,<task2>...
SBT Tasks to be executed. i.e. compile
-d /path/To/dependencyFile.json | --dependencyFile /path/To/dependencyFile.json
optional file where the dependency buffer will be stored
-l | --search
load and search dependencies from remote repositories
-g | --generateConfigurations
generate dependency configurations
-c <value> | --findByNameCount <value>
number of dependencies to resolve by class name per jar
https://bitbucket.org/mnyx/universalresolver
My question is, is there a wizard or automatic importer for converting an existing Eclipse Java project to a Maven project, using the Maven plugin?
As far as I know, there is nothing that will automagically convert an Eclipse project into a Maven project (i.e. modify the layout, create a POM, "generate" and feed it with metadata, detect libraries and their versions to add them to the POM, etc). Eclipse just doesn't have enough metadata to make this possible (this is precisely the point of the POM) and/or to produce a decent result.
Or should I create a new Maven project and manually copy over all source files, libs, etc
That would be the best option in my opinion. Create a Maven project, copy/move sources, resources, tests, test resources into their respective directories, declare dependencies, etc.
For converting to Gradle is analogue to Maven:
Right click on Project -> submenu Configure -> Convert to Gradle (STS) Project

Categories