Using Maven to build a Java Web Start application - java

I'm new to almost all related things, but would like to build a Java Web Start application using Maven. I also need to repack a specific .jar (commons-httpclient-3.1.jar), or it won't sign with JarSigner (looks to be a common problem when I googled). Perhaps I could use this Maven plugin, but I don't even know how to setup the Maven repository.
I (might) need to:
set up the Maven repository to be able to use the above plugin,
configure the jnlp build using the plugin,
take use of three .jars that we have developed (already built using Maven) and install along with the dependencies (such as slf4j-api-1.6.1.jar, spring-security-core-3.0.7.RELEASE.jar and a dozen or so others),
also unpack and repack a specific .jar (repack using jar.exe, not zip since it doesn't work).
I much prefer examples to links to big chunks of documentation. :) Thanks in advance!

you can use a maven plugin for web start
Alternatively you can generate a war with the jnlp file inside (created manually)
You can even create a servlet that will create a jnlp (with stuff like get all jars in some lib directory) and return dynamically to the client.
The plugin should be in the maven repository, but I've never checked it...

You've probably figured this out by now, but plugin repositories are referenced with a separate configuration in your pom to the normal installation repositories.
e.g.
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
See here http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

Related

Maven can't download dependency

i have a big problem since this morning. prefix that i already checked if this problem was solved but , tought ther are simylar problem, my error persist.
the problem is that when i'm trying to add a new dependency in the project pom ,maven can't download and says "could't solve artifact .." , in the m2 repository, for example imagine that i'm trying to add postgresql dependency, in the postgresql folder there are only lastUpdated file . i know it means that maven create this file because it can't download it and they "remember" that but, why?? i tryed everything from other similar post, like build clean install -U , or deletting from cmd all .lastUpdated file or cleaning the workspace and create a new one but unsolved my problem. the funny thing is that when i change the project in another eclipse workspace (and the settings associated to them) it goes. my friend have the same configuration (settings ecc) of the project and he doesn't have this problem, so i think isn't a problem of settings.
have you got some advice for me? i not posting any code but if you need something i will do.
thanks
This case had troubled me for a while, just add a repository in your project pom.xml. And this can solve my problen bellow, have a try and good luck~
<repositories>
<repository>
<id>maven2-release</id>
<url>http://uk.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>oss-snapshots</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
I have that problem sometimes, especially in the work network.
I have 2 variants which help me to solve that problem:
1)Just go with your Terminal into the directory and run "mvn compile". Then it should work.
If not you can try to Invalidate the Caches and Restart IntelliJ:
File->Invalidate Caches & Restart"
2)If you also use Idea, you can change maven version from its on yours. In my case, I changed from maven3 to maven, which I have on C:\maven. After that, all dependencies would be downloaded
Maven is more of a convenience that saves you from needing to go out to the world wide net, and manually download all the jar files. It isn't always perfect.
I recommend that you manually look up and download the jar file you need on the interweb.
Then, use this format at the command line to manually add it to your Maven repository:
mvn install:install-file -DgroupId=javax.example -DartifactId=example -Dversion=1.0.0 -Dpackaging=jar -Dfile=jta-1.0.1.jar
(above was just an example and you will need to look up the specifics for your jar file. )

Best way to work with online dependencies in Java

First of all, sorry about my bad english.
Well, I've got a Minecraft server and, for those who don't know, it works with Java plugins. To create a plugin, it's needed to import a dependency(the jar that runs the server).
Since I need to modify those dependencies sometimes, I've got to keep them on my Dropbox, 'cause I work together with other developers.
I started to think about easier ways to achieve these goals. After a little research I found out about maven and I tried to use Artifactory and Nexus but I keep having a lot of problems with both: My IDE(just started to use Intellij) just doesn't find the .jar in the repository manager(also verified on Eclipse and NetBeans).
-------- QUESTION STARTS HERE --------
So, what's the best and simplest and easiest way to have those dependencies online(I've got some Linux CentOS servers to host them) in order to be able to import them and keep it updated(even if it's cached locally) without the need to work with the files?
Artifactory or Nexus are good ways to do this.
You will need to configure your IDE(s) to point to your repository or adjust your Maven pom.xml files accordingly, as your repository is not the default one for Maven (called Maven Central, accessible from a web browser at http://search.maven.org/).
Here's a slightly edited excerpt from a pom.xml file I use:
<repositories>
<repository>
<id>fooco-repositories</id>
<url>https://build1.fooco.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
</repository>
</repositories>
See "Using the Internal Repository" on http://maven.apache.org/guides/introduction/introduction-to-repositories.html
It may be overkill - but as suggested above, setting up a nexus server is probably what you want.
Most likely the artifacts you're looking for won't vanish, but the key to the configuration is your "settings.xml" which typically you could find here:
"~/.m2/setting.xml"
Within there, you can have the "repositories" stanzas listed above plus the "servers" stanzas which allow you to set user/pass combos for deploying to different repos within.
If you're sharing across the internet, you're probably going to want to harden your nexus server, turn on/up auth, etc., beyond the scope of this posting...
The easiest way (not the best one) is to create a GIT repo right here for example - https://bitbucket.org/ and put your sources with all the JARs you need. To build you project you can use maven/gradle/ant+ivy.

blacklisting a maven repository

When I run an integration test for my project, it is trying to search in a repo that is being pulled transitively and I need to wait for time out. I blacklisted that repo like this.
<repository>
<id>seacrh-snapshots</id>
<name>Exodus Snapshot Repository</name>
<url>http://repo URL/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
but it is still pulling this repo when I run the IT test:
Downloading: URL repo/maven-metadata.xml
Is there anything else that need to be changed?
I strongly recommend to use a Maven Repository Manager such as Nexus. It will help you to get stable and reproducible builds with Maven. You can disable Repositories there (or Nexus can handle this for you as well).
http://www.sonatype.com/books/nexus-book/reference/maven-sect-single-group.html
http://maven.apache.org/repository-management.html
Normally, when maven runs it goes to fetch artifacts in the following order
it check your local .m2/repositories folder
if it can't find the artifact then it reads your pom / parent pom/ super Pom / user level setting.xml/ global setting.xml - in that order to find external repositories to download the artifacts from, usually these repo are either directly from the internet (like the pre-configured default maven repositories) or local private repo managers(like nexus, Artifactory).
Maven will execute the repo as in the order in which they are declared.
First of all, check your project effective-pom that nothing else is overriding your configuration. either in the terminal by typing mvn help:effective-pom on the project root dir or easily in eclipse "effective pom" view of your pom.
Otherwise, it's a good use-case for you to consider installing local repository manager as you would not always need to fetch externally your third party dependencies everytime you run maven.
i would recommend Artifactory much better than the nexus.

Maven coordinates for vert.x?

I am trying to add vert.x in a maven project, but it seems like it is not in the central repository. Am I wrong?
If it is available from Maven, what are the dependency coordinates? Thanks.
We haven't uploaded vert.x into Maven Central yet, but it is near the top of the TODO list.
I'll update this post when it's done.
[UPDATE]
The next release is imminent and will feature a Gradle-based build and Mavenised modular components, amongst other things.
The Maven co-ordinates will be: "org.vert-x:vertx-%stuff%:%version%".
(Note the dash: The project doesn't currently own the org.vertx domain, so Maven wouldn't let us use it.)
[UPDATE2]
vert.x 1.2.1.final was released into Maven Central, with coordinates as above.
In Gradle for example:
repositories {
mavenCentral()
}
dependencies {
compile "org.vert-x:vertx-core:1.2.1.final"
compile "org.vert-x:vertx-platform:1.2.1.final"
}
See http://github.com/vert-x for examples of how we're using Gradle to build modules.
If there are no vert.x artifacts in public Maven repos you can distribute the library with your project using a local (project based) repo using:
<repositories>
<repository>
<id>local-project-repo</id>
<url>file:${basedir}/lib/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
After that, you only need to recreate a Maven repo structure (groupId, artifactId, version) in /lib/repository.
This approach will prevents you the need to install the vert.x dependency in each environment you want to compile the project.
I couldn't see a "pom.xml" file in the vert.x source code rep, or a Maven artifact in Maven Central, so I think you are out of luck ... for now.
You could always download the vert.x sources, do a local build, slap together a minimal POM file (with your own invented group/id/version) and install it into your local repo. That will tide you over until the developers complete the Maven-ization and publication.

install maven plugin locally

I believe there's a maven command you can execute to download and install a plugin in the local repository. Something like:
mvn plugin:download -DartifactId=maven-war-plugin
-DgroupId=org.apache.maven.plugins -Dversion=2.1.1
-Dmaven.repo.remote=http://www.ibiblio.org/maven,http://maven-plugins.sourceforge.net/repository
I know that this should normally happen when you build a project whose pom.xml references this plugin, but the security policy where I work is abnormal, so I need to manually install plugins.
The syntax above doesn't seem to work, does anyone know how to do this under Maven 3.0.2?
The above syntax is for Maven 1.0, which operated very differently from Maven 2.0 and Maven 3.0. You should continue to reference the plugin as you would - via the POM in this case or via the command-line directly for some types of commands. To strictly control what artifacts get downloaded, you can use a repository manager (such as Apache Archiva, Artifactory or Nexus) to intervene (as well as add several interesting features).
Here is how to force Maven to use the managed repository instead: http://archiva.apache.org/docs/1.3.4/userguide/using-repository.html
You can either add only the artifacts you want to use to that, or configure rules about what can be retrieved externally (e.g. http://archiva.apache.org/docs/1.3.4/adminguide/proxy-connectors.html)
The optimal way to deal with plugin and other artifact installation is to implement an instance of a Maven repository on your LAN. Products such as Nexus are open-source and easy to set up. Once up and running, upload your Plugin manually to Nexus. Then add your own local Nexus instance as a plugin repository inside of the settings.xml file for the developers who need it:
<pluginRepositories>
<pluginRepository>
<id>mycorp-plugin-release</id>
<name>My Companys Nexus repository for plugin artifact releases</name>
<url>https://intranet.mycorp.com/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
Seriously...it'll take a day to set up initially, but will make your life easier and shouldn't violate ANY security policy. It'll also help to ensure that all developers are using the exact same version of the plugin.

Categories