I am using play 1.2.4 to create a web app. It works together with some other applications which are maven projects: they are compiled and resolved (dependencies) with maven.
Now I need to modify my play app so it can also be compiled and started with maven.
Therefore I download maven (3.0.4), installed the maven modul and did everything according to https://github.com/wangyizhuo/play-maven and http://www.playframework.org/modules/maven-head/home
I manage to automatically create a pom file in my project. The problem is that the jars from the play framework are not copied into the lib-folder and when I try to execute mvn package they are missing.
Is there a way to get the maven module to work properly? If not, is there another possibility to compile and start the project from maven (i.e. intermediate ant-file that can be executed by maven?)
Many thanks in advance!
This explains it pretty well. I havnt looked at the module you are refering too, but this shows you how you can create tasks and inculde directories in your build.
Do you need to use maven to build/run it? If not it looks like there is a community contributed extension that allows you to use maven from within play.
Related
I'm writing a lot of plugins for minecraft bukkit server's and I've grown tired of copy+pasting the same utility classes in my projects all over again. I decided to just put them all in a separate project and add them to my plugins via maven. I'm using IntelliJ Ultimate.
I want to have a maven project that contains all my utitily classes called e.g. UtilityAPI. Then I want to be able to create another project, which will be my bukkit plugin. In this second project I want to be able to use all the code from the first one. Also, I'd like it very much, that if I choose to build a plugin jar, maven automatically takes into account the most recent code from my API-Project.
I started working on this and started reading about maven modules and how you can use them to forge different projects together. I initially thought, that this was just what I needed, and tried to just add
<modules>
<module>UtilityAPI</module>
</modules>
However this results in my bukkit plugin project being considered a parent project, and refuses to build in a jar, but just in a (at least for me) rather useless .pom file. I'm not sure how to proceed. Do I have to create a "parent" project for my bukkit plugin project which contains the api and the plugin project as modules? And if yes, how do I generate a .jar, and not a .pom?
The dream solution would be to have the UtilityAPI project, and being able to include it in any new plugins that I might write in the future. I'd also be a fan of having a simple way to create a jar with the newest sources of my plugin in it. Is this possible, and if yes, how?
In your Maven multi-module project your plugin would have to be another module (and not the parent, which has packaging type pom). This module would then have a dependency on the API module (dependencies between modules are possible).
However, multi-module projects are usually intended for projects which are tightly coupled. That does not appear to be the case for your scenario. It sounds like the plugins have (potentially) nothing in common except for the dependency on the API project. Maybe it would be better to have the API project as separate standalone Maven project and then deploy snapshot versions of it (or install them only to your local Maven repository) and use these in your plugin projects.
I have the following situation:
I am trying to write a little project in Java which should produce a single EAR file which contains a single WAR. There might be some JARs in the future, but it is not important now.
I need to use gradle for build automation and Intellij for developing. I have some problems with synchronization between those tools.
I have prepared a gradle project ‘ear-app’ with the ‘ear’ plugin applied. It depends on a second project ‘web’ which is war. It works well with gradle wrapper. ‘build’ task builds ‘ear’ file.
Unfortunately Intellij has not recognized the
‘ear’ artifact. In “Project Structure”, there is only web application artifact which comes from ‘web’ project.
Is it possible to make Intellij be able to recreate ‘ear’ artifact?
I do not keep intellij files in my repo, so I need a solution which bases on gradle configuration.
Seems like this was asked over here in the meantime, and got this response from ɐuıɥɔɐɯ:
Seems automatic artifact configuration is not implemented yet in IDEA
Long title, but pretty much explains it. I've pulled a git repo (spring rest tutorial http://spring.io/guides/tutorials/rest/) which contains multiple standalone java projects each in separate folders. Each of these projects contains gradle build files as well as gradle itself (no need to install gradle), AND the necessary Spring jars (likely in the gradle-wrapper jar). I've created a java project in eclipse that mirrors one of the folders and the changes in eclipse are picked up no problem and it builds fine.
The problem I have is that the Spring dependencies aren't on the Eclipse build path, so I can't use all of the nice Eclipse features (function completion, auto imports, etc.). There's only one jar in each separate folder from the git repo and it's called gradle-wrapper.jar. My guess is that this contains all the Spring dependencies, as the project builds fine, assuming I've typed everything correctly and manually added correct import statements.
Is there a way to set this up so that I'm not getting all these ugly errors in the java project? I attempted to add the gradle jar to the java project build path, but this had no effect. I suppose one option would be to add the spring dependencies separately, but then the Spring on the build path wouldn't necessarily match the Spring dependencies used by gradle for the actual build.
Gradle projects don't package all the dependencies in the repository; one of the primary reasons to use Gradle or Maven is that they'll handle dependencies for you. You need the Gradle Eclipse plugin and to Import->Existing Gradle projects.
I work on a big Java application and I'm having problem compiling it under Eclipse Kepler:
the application is based on Maven 3.1.0 and successfully compiles there
I generate Eclipse configuration (project files) using mvn eclipse:eclipse
The problem is that certain classes present in more than one JAR (e.g. imagine a class Http and two versions of this class where newer has more methods) and Eclipse makes a wrong choice of the depending class (older one) for particular project which makes it not compilable.
I tried to move Jars up/down in the project dependencies and it helps in certain situations, however, it means that I'm changing configuration changed by Maven.
Is it possible to configure Eclipse so that is "smarter"? Is it caused by Maven (POM files, a bug in Maven's eclipse plugin, ...) although maven compiles the project without any problems? Any other suggestion?
You should not use mvn eclipse:eclipse. The official way today is to use the m2e plugin (which is much smarter) with File->Import->Existing Maven projects.
When you open a pom.xml file you can see the dependency hierarchy and why a given jar was chosen.
(Note that most but not all standard distributions of the latest Eclipse contains m2e. If your do not you can download it from the marketplace, but it may be easier to download a distribution that has it).
I am updating an existing project from GWT 1.5.2 to GWT 2.0.0. We use maven 2 to manage our dependencies and do all of our development in Eclipse 3.5.
Because we use maven to manage our dependencies, I do not have all of those jars in the war\web-inf\lib directory as GWT specifies. Instead, they are in the maven repository, just where maven likes them. I have the project set up so that maven can successfully build and launch in either dev or web mode and the application runs correctly.
The problem is that when I launch from Eclipse, I get a java.lang.NoClassDefFoundError. If I manually copy of my dependencies into war\web-inf\lib before launching, everything runs fine, but that doesn't lend itself to a long-term solution. First, if I check all of those jars into our version control, that will subvert much of the value we get from maven. As annoying as maven can be, ditching it is not the answer. Second, having developers manually copy them over every time they want to debug something is ridiculous.
So can I get Eclipse to copy the dependencies into war\web-inf\lib before launching? Is there an alternate solution that I'm missing?
Thanks,
Tony
Running the gwt:eclipse goal will copy the maven dependencies into war/WEB-INF/lib. See the Eclipse Configuration section of the Eclipse IDE Integration documentation of the Maven GWT plugin for more details. Also have a look at this answer about Maven GWT 2.0 and Eclipse.
You should install the m2eclipse plugin and use that to build your project within eclipse. This will invoke maven as an external tool from within eclipse.
Your maven project artifact type should be set to war, which will let maven discover the dependencies and bundle them.
See these links:
force Maven2 to copy dependencies into target/lib
http://maven.apache.org/plugins/maven-war-plugin/
http://maven.apache.org/plugins/maven-war-plugin/examples/rapid-testing-jetty6-plugin.html
a maven aware IDE (idea, eclipse, netbeans) should do this packaging automatically. maybe you:
forgot to enable maven import inside IDE?
did not add these dependencies to the pom.xml (so they aren't included in the 'mvn package' phase)
added wrong scope to dependency declaration (e.g. scope 'provided' or 'tested'), so they are ignored for runtime
If you have the packaging method in your pom.xml set to war it should copy runtime depdencies into target/war/WEB-INF/lib.
Or is your project to build something larger like an ear? If so you should probably split your pom.xml into multi-project format.
As for Eclipse, I'm not terribly familiar with it so I can't really help you there. Are you (or can you) run a maven target (like "install") when you do a run or debug?
This is not supposed to be a problem. If you are using Eclipse+WTP then WTP lets you declare jars listed under 'J2EE module dependency' in the project's properties. Those jars are automatically published to tomcat (see note at the end of this comment)
You need to declare an M2_REPO variable in your eclipse environment (search eclipse help for 'classpath variables'), it should point to your local maven repository, and just add external jars from there to your project and mark them as 'J2EE dependencies'.
I did that with tons of projects, Maven and Eclipse live side-by-side :) (without m2eclipse)
A second option is to try to integrate Eclipse and Maven with m2eclipse plugin, as crowne mentioned, but I found this unnecessary.
There is a third option, if you don't use WTP (but you should). Assuming that you use tomcat, then you can copy those jars to $(tomcat.home)/common/lib. If you can do it just for your private instance of tomcat (on each developer's machine) then you are good to go.
This is supposed to be a low-impact solution that will get those jars into the classpath at runtime, but it doesn't scale well.
note: unfortunately the classpath of Eclipse web projects can be confusing. When you add jars to the regular build path of the project, they are not deployed (copied over) to tomcat. To solve this, WTP defines a special library called Webapp Library - this library contains all the jars in the project's WEB-INF/lib folder, as well as all the external jars that are marked as J2EE Module Dependencies. All those jars find their way appropriately to WEB-INF/lib when published to tomcat.
Quite simple:
1. Create a "lib" folder under your project like this:
"\src\main\webapp\WEB-INF\lib"
2. Copy needed "jars" etc that you want included inside your WAR bundle folder.
3. Invoke your maven build as you normally do. I use "mvn install", which creates builds the war file.
If you examine the WAR file, your jars that you included in step-1 and step-2 will be there.
Cheers.