What is the connection between maven and my application? - java

I need to build java project. The project should include two modules: domain and web.
The domain module contains all the entities, the business logic and hibernate integration.
The web module should be depend on the domain module and contains web application using apache wicket.
I wonder about the maven usage.
Should I create a project and modules using maven? If so, how?
What kind of archetype are relevant for my project and modules?
What is better experience - create the project myself or use maven?
I am using intellij.

I'm assuming you don't need a server for others to access your code,
but rather, you want to use maven/ant for internal project
organization/dependency resolution/source organization.
Should I create a project and modules using maven?
Yes, either maven or ant will be useful for any non-trivial Java or Java EE project with external dependencies, and build/testing requirements.
If so, how?
Either ant/maven will allow you to easily setup a platform independent "build" file, so that you can easily resolve dependencies, build your jar executables, and run unit tests in order by issuing a single command, rather than multiple clicks to different plugins in whatver the ide-of-the-month is. You can do this in eclipse using the maven plugin to create a new maven project, or , as you suggest, by creating an artifact by running the regular mvn install.
What kind of archetype are relevant for my project and modules?
To learn use maven-archetype-quickstart.
For a regular (simple) j2ee app, try maven-archetype-webapp.
There is also a j2ee archetype as well.
What is better experience - create the project myself or use maven?
A simple, 3-step, robust method for setting up a maven project :
1) Use maven archetypes to create and setup your "hello world" project.
2) Import the maven project into your ide as a java project.
3) Edit/refine/fix code in your IDE, but use maven to build and test the whole application.
Update: external web frameworks
Creating a wicket (or gwt or any other framework) oriented web app will
Be best done following specific tutorials related to the framework itself. In order to add theframework libs, just paste the maven info in your pom.xml like thus, and run a "mvn install" command :
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-core</artifactId>
<version>1.5.3</version>
</dependency>

I'd recommend you to use maven. The reasons why I use maven:
IDE agnostic. You can use idea, eclipse or some other ID.
Dependencies management
Powerful plugin system
You can manually create 3 maven module
app.parent with pom packaging and no parent.
app.domain with jar packaging and app.parent parent
app.web with war packaging and app.parent parent
and import app.parent to idea.

Also checkout Wicket quick-start Maven archetype creation page http://wicket.apache.org/start/quickstart.html

Related

How add alfresco extension to project which is build on alfresco maven sdk?

Suppos that repo and share module were generated from maven alfresco archetype as described here. And now it needed to install one of alvex addons. It is clear that jars/amp can be build from sources, but what to do with this? Where to put they in generated maven project to get them installed in alfresco when mvn integration-test -Pamp-to-war is executed?
That tutorial assumes two separate maven projects created using the repo archetype and the share archetype, respectively.
If you want to be able to run integration tests with multiple AMPs you may rather use the all-in-one archetype instead.
See How to use external AMP in alfresco Maven Project

Can I avoid storing a Jar file in my repository for unit testing with travis-ci?

If I have a repository setup for unit testing with travis-ci from what I can tell I have to include the JUnit .jar files within the repo so that travis-ci can find them.
Is there a way to avoid storing the .jar files for JUnit itself?
EDIT This is the repository: https://github.com/krisives/jbloomer
Travis CI have a page on Building a Java project. That page lists three ways they support building Java projects: Maven, Gradle and Ant. Maven and Gradle have support for dependency management, but Ant does not. Your project should switch to Maven/Gradle, introduce a dependency manager (such as Ivy), or hand-roll a half-baked, custom solution (i.e. you can call whatever Ant target you want). Maven, Gradle or Ivy would be preferred solutions (IMO).

Maven compile dependency instead of taking it out of the local repo

I am sorry i don't know maven good enough for the complex environment i am currently working in (1k+ applications, most of them are Java EE). I still give it a try to describe what i want to archive:
0.) There is a company framework that abstracts the Java EE World a bit and is used in all the Java EE components
1.) I checked out the maven project of the Java EE component i am working with
during the build it downloads the dependencys of other components out of the companys repository and stores it inside my local repo for compilation. So i can see the jar-files of the companys framework inside my local repo.
2.) I now want to change some of the frameworks functionality for a local test so i checked out their sources from another SVN repository. I made the changes and build that framework component with maven "clean install".
3.) I rebuild the component i am working with as well.
Inside eclipse i can now click on one of a frameworks classes method and it opens the according source. But this only happens because the local repo is meant to contain source-jars for any dependency as well. So in my editor i can see this source is from the jar of the framework in my local repo and i cant change anything.
Could someone please give me a hint how i can archive the following:
I can make changes to the framework (and build the frameworks jars with "clean install")
I can build my component and it uses the above compiled framework jars rather than the "old" ones from the local repo.
I will right now start to read the entire maven documentation and each and every section (i try to understand that dependency management since 1 year and still don't get it) but i would really appreciate if you could help me out a bit here.
I don't know how Eclipse manages maven dependencies, but
In IntelliJ IDEA this is simple - if maven dependency is in project then IDEA uses it instead of dependency from local repo.
So if u want to edit framework source code and use this changes immidiately - i think that framework should be in your Eclipse Workspace. And your module in Eclipse should reference framework artifacts directly - not over Maven dependency mechanism.
I think that this is a Eclipse Maven plugin responsibility. Do u have any installed Maven plugin for Eclipse? (M2Eclipse for example)

How to run wicket examples?

I am new to web prog. and wicket, so i went to below site to run example source codes to play with applications.
http://www.wicket-library.com/wicket-examples/index.html
Simply i create a "dynamic web project" and try to copy source codes to project.
All example's application classes are that type,
public class ...(ex.name).Application extends WicketExampleApplication
On the internet i found some of those examples with classes WebApplication, and i managed to run those examples, like that
public class ...(ex.name).Application extends WebApplication
So my question are;
1-How can i simply run those examples using dynamic web projects?
2-Copying source codes to my project after that how can i call libraries in my project using maven?
I searched many questions but couldnt find any topic who is trying to run those examples simply in a project.
Thanks.
Soso
instead of doing all the messy work just run mvn using tthis
[http://wicket.apache.org/start/quickstart.html]
now just copy the sources
if you any problem and you want to add wicket to an existing project just copy the web..xml , wicket jars and you would have wicket project (i would recomend wicket from another opm connecting you existing services and this way decouple services from the web container ...)
P. S the WebApplication thing they just inehrited it and called ExampleWebApplication
The best you can do is to use maven integration
Install Eclipse (that support Java EE)
Add all required maven related plugins
Version Control: Use Subclipse 1.8.x, see: http://subclipse.tigris.org/update_1.8.x
Maven Integration: m2e , is included in Eclipse Classic. Use
Help->Install New Software, select "--All available sites--" and
choose Collaboration -> m2e - Maven Integration for Eclipse
Subclipse/Maven Integration: Update site: http://subclipse.tigris.org/m2eclipse/1.0/
Then, just checkout the maven examples you got on the web
Go Eclipse--Window-->Show view-->Other
Type svn and select SVN repositories and open it
Then copy the check out address and add it to the svn repositories View
finaly, right click on the link you have added and check out as maven projects.
If you want to create new Maven projects
Create new maven Projects, new-->project-->Maven project
then in new Maven Project Window, in the Filer Text box, Type wicket and select org.apche.wicket as a groupID
After that, you can have your maven codes working well.
If still you got some debug errors, you can open your pom.xml file and add dependencies such as wicket-core and wicket-extensions

How to create a cross project source release with Maven

I have a project I need to release the source for. The problem I have is that I need to create a source release for all code that we have developed. The code is across multiple projects, but I want to leverage maven so that only the source for the jars we are actually using is released.
For example:
core code project (multi module maven project)
web app project (multi module maven project). Contains we app module plus some supporting jar modules. Depends on some jars from core code project.
Now I want to release all the source for the web app project but only the source for the core code project that the web app uses.
Can I do this with maven?
I have a feeling it is possible with assembly plugin and source plugin but it is not clear to me how to put this together.
First of all your question is bit unclear. let me assume certain things and proceed.
I believe that following is your folder structure.
web app project
some source code folder
pom.xml
core code project
some source code folder
pom.xml
Take the core code project and change the version from previous version in pom.xml.
let 's say if it was 1.0 change it to 1.1
<groupId>core code project related</groupId>
<artifactId>core code project</artifactId>
<name>core code</name>
<version>1.1</version>
Make your changes to accomodate the web app project in core code project.
later,
in web app project add dependency for core code project in pom.xml
<dependency>
<groupId>core code project related</groupId>
<artifactId>core code project</artifactId>
<name>core code</name>
<version>1.1</version>
</dependency>
In this way, 1.1 version of core project will have only web app related code.
Currently we are using this method. Hope it helps. let me know if you want something else.
I have a feeling it is possible with assembly plugin and source plugin but it is not clear to me how to put this together.
If I understood the question correctly, one solution would be to create an "aggregator" project listing all wanted modules (the relevant modules from the webapp and the relevant modules from the core) and to use the source:aggregate goal from the Maven Source Plugin.
I'm unsure why you want to do this, the pom from your web app project will explicitly list the versions of your code dependencies used, so you can find the source easily. It sounds like you want to store the same artifact twice. So if your web app uses core-x-1.2.3.jar and core-y-4.5.6.jar you would produce a web app sources artifact containing the source from both those core jars in addition to the actual web app source?
You can use the maven versions plugin to update your web app pom to use the latest versions of your core dependencies, I've automated that by running a shell script in a CI server in the past. That means whenever you release a new version of your web app you will be using the latest release of your core code, and all you need to do is update your web app pom from version control.

Categories