I've just been asked to work on an existing Java EE web project.
The project contains a lot of modules, some EJB packaged in a EAR and a web part inside a WAR.
What is bothering me is that you actually need 1h30 to compile the whole stuff.
And I found this inside the parent POM betwen the plugin managment part :
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
<generateClient>true</generateClient>
<clientIncludes>
<!-- Includes only service interface and business delegate. -->
<clientInclude>**/*Service.class</clientInclude>
<clientInclude>**/*Delegate.class</clientInclude>
<clientInclude>**/ejb/*EJBRemote.class</clientInclude>
</clientIncludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Build-Time>${timestamp}</Build-Time>
<Implementation-URL>${project.url}</Implementation-URL>
</manifestEntries>
</archive>
</configuration>
</plugin>
Doesn't this means that every module is being "parsed" by the EJB plugin?
even non-ejb modules?
Thanks.
ps : the parent pom also have some dependancies that also are inside the modules' pom.
I totally forgot this : I found the solution and then the project "only" needed 15 minutes to be compile.
The java version needed to be upgraded, from what I remember there is some kind of bug with maven and java 1.6 version xxxxx.
At the time upgrading to the lastest version of java 1.6 solved the problem (or it was 1.5 I don't remember).
Related
I know that there's a lot of question related to this issue but none made sense for me. I built a Java Desktop application that adds products for sale by communicating with an API. I am using okhttp 3.9.0 to accomplish this task. The problem is that my app works just fine when I execute the Netbeans' "run project" command but when I use the "java -jar file.jar" command to run the app I get exceptions stating that okhttp3 classes weren't found. That's the first time I try to run a Java application outside of an IDE so I kind of lost.
I am running my app from:
C:\Users\Diego Alves\.m2\repository\com\mycompany\loja\1.0-SNAPSHOT
Also, something that bugs me is that when searching for okhttp3 I generally end up on an Android-related page. Isn't okhttp3 used for desktop apps?
You need to add dependencies to your jar(okhttp is one of them) so that the JVM can find them in your classpath. To do that, in pom.xml add the following plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>your.package.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Also make sure you have set <packaging>jar</packaging>
Then run the build (mvn clean install), it will generate a jar that can be executed successfully.
java -jar target/your_jar_name.jar
For OkHTTP there is no link with android, you can use it in any Java Application.
In a web application where should I mention and track the version number?
I'm using maven, which has version element in pom.xml. However, I cannot trace back that version number after packaging as war. Though, that version number is stored in the filename as applicationname-1.0.1.war. I wanted to know if it stores somewhere within the package or any way to do it?
Use the maven archive plugin to store it in the WARs Manifest.
If stamping the version in the MANIFEST is good enough for your needs then you'll want to configure the maven-war-plugin something like this:
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Repository-Rev>${SVN_REVISION}</Build-Repository-Rev>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
...
The children of the manifestEntries element can be anything and will create entries with given name. In this example, there would be entries of "Build-Repository-Rev" and "Build-Time" created using the "SVN_REVISION" environment variable and "maven.build.timestamp" property in addition to the entries created by the "addDefaultImplementationEntries" which would include an "Implementation-Version" entry set from ${project.version}.
I am developing a Java maven project with Eclipse and want to export a jar that includes all referenced libraries. These referenced libraries fall into one of these two categories:
They are explicit (or implicit) dependencies in the pom.xml
I have some libraries not available as maven artifacts and have put them in /lib (and added them to the build path in Eclipse)
There's the maven-assembly-plugin, which works fine for 1). However, I'm unable to find a maven plugin that also includes non-maven-dependencies, e.g. "all jars in /lib".
Then there's the Eclipse FatJar plugin, which sort of works, but hasn't been updated since 2009, so it seems unmaintained. Also I prefer an export method that I can directly specify in the pom.xml.
Can anyone point me to a maven plugin or the like to export all referenced libraries, including those from case 2) ? That only needs to involve putting them in the jar and referencing them in the manifest's classpath.
Thanks!
I think the best way to handle this is to include your custom libs into a local maven repository. Now you can inlcude your libraries as maven dependencies and you can export all your dependencies specified in your pom with the maven-assembly-plugin.
Here is a tutorial, how to put your libs into a local repository in maven to use it in your pom. http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
And in your pom.xml:
<!-- setup jar manifest to executable with dependencies -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
This looks like a task for Tycho. It is a set of maven plugins that allows to create eclipse plugins with maven. Tycho considers manifest entries as build dependencies.
However I'm not aware of how to package all those dependencies in a single jar. This may also be conflicting with the osgi spec. But if you wish to ignore osgi you could just try the jar-with-dependencies assembly.
I have some problems with my .ear file. The structure of the file is:
app.ear
|-xxx.jar
-yyy.jar
-zzz.jar
-ektorp.jar
-app-ejb.jar
-app-web.war
|-WEB-INF
|-lib
|-xxx.jar
|-yyy.jar
|-zzz.jar
|-ektorp.jar
When I try to deploy my application, I get ClassNotFoundException, with class wihch is in ektorp.jar. This file is used by ejb module.
I also don't know why these jars are doubled? In ear and in war module are the same .jar files.
Ear is built by maven2.
When I try to deploy my application, I get ClassNotFoundException, with class which is in ektorp.jar. This file is used by ejb module.
Does the EJB-JAR reference ektorp.jar in the Class-Path: entry in the manifest (see Packaging EJB 3 Applications for more background on this)? The FAQ explains how you can configure the plugin to generate a Class-Path: entry in the manifest:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.2.1</version>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
Just in case, do you know that you can package EJBs in a .war with Java EE 6 (the difference is that all classes are loaded with the same classloader when using the .war packaging)? If you don't have strong modularization requirements, the .war packaging is simpler.
I am facing another problem in my little test-webapp.
I have an EJB module (created via maven-pom) that basically wraps the data-access, so all it does is some DAOs implemented as Stateless-SessionBeans. My domain-model (simple POJOs with JPA2 annotations) is located in another, simple java, project that will be packaged as jar-file.
When I create the enterprise-archive, maven only puts the webapp and the ejb-module into the application.xml and even when I change this manually the ejb-module cannot find the classes from the domain-module at deployment time.
I read something about that an ejb has to have all its dependent jars within its own archive but I cant believe that since this domain-module is used by other projects as well.
How would I package this (or set it up in maven) so my ejb can load classes from an external jar?
thanks
If I remember well, simply generate a manifest with a Class-Path entry in your EJB-JAR:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
...
</plugins>
And add your external jars to the EAR. To do so, declare them as jarModule in the Maven EAR plugin configuration. See modules configuration.