I currently started my JavaEE course at the faculty and I installed Eclipse for JavaEE. I installed JBoss 7.1.1 from the Eclipse Marketplace and I started developing applications, all worked fine.
Now, I reached a point where I need a specific library (Apache Commons IO) that the server has as a module. The point is I need to get this module in the development environment somehow. I added the JAR from the server folder to the WEB-INF/lib folder and as a JAR dependency in my project, but I think there is a more elegant solution.
Is there a way I can automatically add the server modules in the Eclipse environment?
P.S.: I must mention that the project I created is a simple Dynamic Web Project, not the kind of project that the JBoss plugin creates and I intend to stay with this type of project because the course asks to develop this way.
Try to use Maven for your development environment.It may be the answer of your question.
Here are some useful links of Maven
Creation of Dynamic Web project with Maven
Guide to using Eclipse with Maven
The solution was to learn Maven and use the m2eclipse plugin for Eclipse. My final POM is looking like this:
<build>
<sourceDirectory>${basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src</directory>
<excludes>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Related
Requirements
I am refactoring a Java application and am trying to move code out of a war file and into a jar file so it can be used across many different web applications. However, one of the requirements is that the developers still need to use breakpoints within the library. To do so I believe I need to package the source with the compiled code. Below is the build lifecycle
Build Lifecycle
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Question
When I run mvn package and mvn source:jar package it creates two jar files, respectively
db-0.0.1-SNAPSHOT.jar
db-0.0.1-SNAPSHOT-sources.jar
Then I can attach the source to the dependency.
My question is two-fold
Is there anyway to package the source code into the same jar file as the compiled classes, and
Would this auto-attach the source code to the dependency in Eclipse, so that the developers don't need to do it automatically?
Putting the source code into the JAR is the wrong approach.
You create two JARs (as shown in your question). These JARs go to the repository. Then everyone who uses the JARS will automatically get the -sources as well. In the usual IDEs, like Eclipse and IntelliJ the -sources JAR is automatically used for debugging.
Instead of two Maven runs, you should add the source plugin to your POM. Then the -sources JAR is created during the normal build.
My Spring Boot project has build description:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.app.MainClass</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I want my JAR file name to be app-1.0-SNAPSHOT.jar in one branch and 1.0-RELEASE.jar in another, controlled by Jenkins (using some kind of mvn settings or JVM argument such as -D..
Can I do this?
So simple, In one branch, you have pom.xml with
<build>
<finalName>app-1.0-SNAPSHOT</finalName>
</build>
In other branch, you have pom.xml with
<build>
<finalName>1.0-RELEASE</finalName>
</build>
You can propagate the version of the project to your build name like this:
<build>
<finalName>app-${project.version}</finalName>
</build>
or the version of your parent project if you have one:
<build>
<finalName>app-${parent.version}</finalName>
</build>
Then you would keep track of you project version rather than the build name.
However, note that managing the build verson in SCM using branches is a pain in the neck and error prone. It is rather recommanded that your code repository woud be agnostic of your build version.
A possible alternative would be to use some release management tool, like maven release plugin, or even more simple maven version.
Example:
Here I'll give and example using maven verion.
Say you're using SCM tool (it could be git) and a build factory (like Jenkins or any other tool). Say you have a job to build and deploy snapshots and another one for releases.
In the snapshot job, you can set-up a pre-build task with the following maven target:
versions:set -DnewVersion=app-1.0-SNAPSHOT
and the following in the release job:
versions:set -DnewVersion=app-1.0-RELEASE
Now doing this is OK, because you are only doing it locally and never have to manage the build version in your code.
Now, you can tag your (release) version after having applied maven version and build successfuly (hopefuly including unit, integration and functional tests). This way you may keep track exactly of the code that has been deployed on each release.
Tip!! Space is money! Do yourself a favour: clean your snapshot repository regularly. Creating a job that does so every once in a while shouldn't be to difficult.
You can specify the artefact-name with the maven boot plugin:
In this case, it will be NewJarName.jar
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<finalName>NewJarName</finalName>
</configuration>
</execution>
</executions>
</plugin>
I want to deploy my src/main/webapp folder from Maven project as an application in JBoss7. What I'm trying to do is to:
save and refresh xhtml, css, js etc.
do mvn prepare-package war:inplace for full deployment
This is of course for development only. I want to have similar workflow as with Maven Jetty plugin but for JEE6 app.
Deployment scanner is looking for *.war directories.
My current solutions:
use jboss-as-maven-plugin to deploy on package phase - with this I need to redeploy on each CSS, JS or XHTML change
add my target folder to deployment-scanner and do war:exploded to copy resources to war dir. Full redeployment needs creating .dodeploy file with antrun plugin and this is quite ugly. I still need to run maven after saving resources. I don't want my resources to be copied anywhere.
There is nothing special in my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pg</groupId>
<artifactId>jeesample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>jeesample</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
<build>
<finalName>jeesample.war</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
Try to use the maven-war-plugin. Maven should add your depenendencies. Note, however, that JBoss 7 has a new module dependency system, so if you want to use some internal modules provided by jboss you have to state them in your MANIFEST.MF file as in the example and mark them as provided in the pom.xml. JBoss 7 reads the manifest and loads the modules upon deploy
Here is an example that works for me:
...
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifestEntries>
<Built-By>Dev Team</Built-By>
<Dependencies>javaee.api, javax.faces.api, javax.xml.rpc.api,
org.joda.time, org.hibernate, org.hibernate.validator,
org.dom4j, org.picketlink</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
...
With this config the correct war is created (mvn war:war). Also when I right click on the project in eclipse and choose > 'Run on Server' the war is deployed correctly. Resources such as xhtml, etc are automatically redeployed on save and the changes are visible upon refresh.
I also have the m2eclipse plugin installed
if you can switch to play framework, this will increase productivity very much. reall... it's like ruby on rails.
Also if you are using maven, probably this can help to automatically deploy EAR during install phase
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>ear</type>
<overWrite>true</overWrite>
<outputDirectory>${jboss-inst}/deploy</outputDirectory>
</artifactItem>
</artifactItems>
<skip>${skip.ear.auto.deployment}</skip>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
</plugin>
This question already has an answer here:
Maven project with JavaFX (with jar file in `lib`)
(1 answer)
Closed 9 years ago.
Is it possible to reference JavaFX 2.0 as a dependency in Maven in the pom.xml so that everything works smoothly?
I saw in this question that it is possible to install the jfxrt.jar locally, but ideally I'd like a simpler approach where the dependency can be properly resolved and downloaded without any local hacks....
here is a possible solution.
Create a lib folder in your project directory and put the jfxrt.jar into that directory.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jfxrt.jar</systemPath>
</dependency>
And if you want to build an executable jar you only need to include the javafx-maven-plugin. For further information see: link-to-github
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<mainClass>[put your application main class here]</mainClass>
</configuration>
</plugin>
No, such a solution doesn't exist for the moment. I doubt that it will ever, since as from Java 1.7 update 2, JavaFX is installed together with the JVM. Plans are to include JavaFX in the JRE as from Java 1.8 (next year). From then on, you wouldn't need a dependency at all.
However you can use Maven with JavaFX now already, because Maven can call Ant tasks (antrun plugin) and there are super Ant tasks available with the JavaFX distribution. I blogged about it, but it's in French: Creer un projet Maven pour JavaFX2. It walks you through the whole process. Nevertheless, if you don't understand French, leave a comment on the article and I will try to help you or look in here in the Oracle forum
The article of Sergey suggests to add javafx as a system dependency, which should not be used. Instead, you can include the following in your POM to install javafx automatically.
<profile>
<id>install-javafx</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>install-javafx</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>validate</phase>
<configuration>
<file>${jfx-runtime}/lib/jfxrt.jar</file>
<groupId>javafx</groupId>
<artifactId>javafx</artifactId>
<version>${jfx-version}</version>
<packaging>jar</packaging>
<javadoc>${jfx-runtime}/../docs/api.zip</javadoc>
<!--<sources>no source available</sources>-->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>install-javafx-bin</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${settings.localRepository}/javafx/javafx</outputDirectory>
<useBuildFilters>false</useBuildFilters>
<resources>
<resource>
<directory>${jfx-runtime}</directory>
<includes>
<include>bin/*.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
If you want to have api docs installed, zip the contents of of the docs/api folder to docs/api.zip. Now you just have to run maven, with the profile activated and the jfx-runtime and jfx-version properties set.
I have a single maven project, which compiles to webapp, with the standard Maven war layout.
I am trying to add aspects to the same project but the aspects are not triggered when deployed as a war on Tomcat. If I deploy the project as a jar, the aspects kick in.
Here is how my pom.xml looks like
```
<groupId>in.sheki</groupId>
<artifactId>abc-service</artifactId>
<packaging>war</packaging>
<name>abc-service</name>
<properties>
<aspectj.version>1.6.12</aspectj.version>
</properties>
<build>
<finalName>abc-service</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<complianceLevel>1.6</complianceLevel>
</configuration>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
....
</dependencies>
</project>
```
The aspect is defined in one of the packages of the project as a JavaClass with #Aspect annotation.
What could be I doing wrong?
To create a war, I do mvn clean install and move the war to the webapps directory.
For creating a Jar, I use the assembly plugin with a Main Class, this does not start the HTTP services but starts the other processes in my code.
Make sure you have a property called war.bundle
true
Have a look on http://maven.apache.org/maven-1.x/plugins/aspectj/
If you are running without spring then you may require aop.xml as described in
http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html
Wars deployed on Tomcat (or any other web container as far as I know) have their methods called through the relection process, and that way does not trigger the "call()" pointcut.
Try switching your "call()" to "execution()", worked for me on a Jonas with maven handling the deployment via cargo.