Compiling LESS CSS with Maven and m2e-wtp - eclipse

I'm trying to compile LESS CSS files with lesscss-maven-plugin, both in pure maven (with command line) and within Eclipse (Juno).
In the lesscss-maven-plugin, I need to define an output directory, but I noticed that in Eclipse WTP copies files from target/m2e-wtp in my server (JBoss), but that this directory is ignored by the war plugin of Maven.
I succeeded to reach my goal with Maven profiles : in Eclipse I use a m2e profile configured in Project settings, so I can define two different destination folders depending on I build in Eclipse or not.
Here is 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.dgadev.motd</groupId>
<artifactId>motd</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<outputDirectory>${project.build.directory}/resources/css</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>m2e</id>
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<outputDirectory>${project.build.directory}/m2e-wtp/web-resources/resources/css</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This works, but is there a better way to do this, without the profile trick ?

I found another solution with a different less compiler : wro4j. With this compiler, both exists maven and m2e plugins.
In addition, a tutorial (for building boostrap) can be found here: m2e-wro4j

The same solution you provided, a bit cleaner :
https://github.com/marceloverdijk/lesscss-maven-plugin/issues/8
The m2e profile is activated with a m2e variable, so you don't have to select it.

Related

java.lang.NoClassDefFoundError using Wildfly, Maven, Rest?

I have 2 Maven projects, and let's say I'm using Project2 as a dependency in Project1.
Project2 is using Java Security and has some encrypting methods.
I ran the command mvn install in Project2 and then this is how I am adding the dependency in Project1:
<dependency>
<groupId> myProject2groupId </groupId>
<artifactId> myProject2artifactId </artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
And I added this in Project2 pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>ProjectJARs/project</finalName>
</configuration>
</plugin>
The import of the classes and methods of Project2 in Project1 are perfectly working, giving me no errors when I try to compile as a Java Application and printing in console.
But when I'm running it on the Wildfly server and applying GET/POST methods from my rest endpoints, it gives me this error:
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: simmetricClasses/SimmetricCriptography
(In Project1 Maven Dependencies I can see Project1's folder with this [without test code])
Can someone help me with this error?
Thanks a lot
This is the pom.xml of the project I want to use as a module:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupId</groupId>
<artifactId>myartifactId</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>ProjectJARs/project</finalName>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Is this correct?

Creating the most basic Scala project with Maven?

I use Maven 3 to create a new Scala project. As far as I understand, the way to create a new project with Maven is by:
mvn archetype:generate
Maybe I'm missing out something, but I couldn't find even one option that offers the simplest Scala project (like the one received by lein new app ... for Clojure, for example). Any help here?
You should be able to use mvn archetype:generate. You can choose, e.g., org.scala-tools.archetypes:scala-archetype-simple. You need to put in the number number next to the archetype name in the output of your mvn archetype:generate command because the numbering can change over time. There are also other options like eu.stratosphere:quickstart-scala as documented in this article.
They may be somewhat outdated, though. I personally prefer writing my pom.xml files manually. For reference, here is a minimal pom file for use with Scala 2.11.6 and Scalatest 2.2.5:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<encoding>UTF-8</encoding>
<scala.version>2.11.6</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>2.2.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Main Scala archetype looks discontinued under the most know address.
This archetype looks much better:
https://github.com/davidB/scala-archetype-simple
using it as for now:
mvn archetype:generate -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple

Cannot add maven dependencies to deployment assembly in ejb packaging

I have a project with a POM that looks like this:
<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>
<parent>
<artifactId>my-parent</artifactId>
<groupId>com.company</groupId>
<version>2</version>
</parent>
<groupId>com.company</groupId>
<artifactId>resources-silo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>Some EJB component</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>simple-command</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- some jars ... -->
</dependencies>
</project>
I want to use m2eclipse with m2e-wtp to deploy this project to Glassfish 3. However, m2e-wtp does not deploy the dependencies. I know that building superjars with jar-with-dependencies is probably not the way to go for EJB projects, but I cannot really change this without messing up the customer's build / deployment processes.
So, the problem is that the deployment assembly wizard does not display the maven dependencies:
I need a solution that works without changing the pom.xml, since that would disturb the customer's build processes. I am aware that using an EAR would be the preferred solution here.
Is the behaviour that I'm seeing a bug or is it an inherent limitation in the way m2e-wtp and the ejb packaging work?
Is it even possible to have m2e-wtp extract dependency jars into the deployed application?

how to solve the dependency missing in eclipse by mvn? [duplicate]

This question already has answers here:
How can I make eclipse make use of packages downloaded by maven?
(2 answers)
Closed 9 years ago.
I get a java servlet project from github, it use mvn to compile ,and use jetty as the servlet container.Since I never used mvn ,so I get much problems/.
question 1:
When I run mvn install , it says "BUILD SUCCESS",but after I import this project into eclipse, many packages imported cannot be resolved by eclipse. Why ?It seems that when I run "mvn install",mvn has downloaded all dependencies for me.
question 2:
How to deploy my project to jetty and then run all jUnit test cases ?
question 3:
when I run "mvn jetty:run",it says:
No plugin found for prefix 'jetty' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/root/.m2/repository), central (http://repo.maven.apache.org/maven2)] -> [Help 1]
Google says I should add jetty plugins to mvn configuration .But I am confused about the project.Why doesn't the project developers add this to pom.xml?Or, there exist other solutions?
below is the simple project directory.Project name is http-request.
[root#localhost http-request]# ls
lib pom.xml README.md
[root#localhost http-request]# cd lib
[root#localhost lib]# ls
pom.xml src target
pom.xml under http-request:
<?xml version="1.0" encoding="UTF-8"?>
<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.github.kevinsawicki</groupId>
<artifactId>http-request-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>lib</module>
</modules>
</project>
pom.xml under http-request/lib:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<groupId>com.github.kevinsawicki</groupId>
<artifactId>http-request</artifactId>
<version>5.5-SNAPSHOT</version>
<url>https://github.com/kevinsawicki/http-request</url>
<description>Library for making HTTP requests</description>
<inceptionYear>2011</inceptionYear>
<issueManagement>
<url>https://github.com/kevinsawicki/http-request/issues</url>
<system>GitHub Issues</system>
</issueManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>8.1.9.v20130131</jetty.version>
</properties>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://github.com/kevinsawicki/http-request</url>
<connection>scm:git:git://github.com/kevinsawicki/http-request.git</connection>
<developerConnection>scm:git:git#github.com:kevinsawicki/http-request.git</developerConnection>
</scm>
<developers>
<developer>
<email>kevinsawicki#gmail.com</email>
<name>Kevin Sawicki</name>
<url>https://github.com/kevinsawicki</url>
<id>kevinsawicki</id>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Require-Bundle />
<Export-Package>!.,com.github.kevinsawicki.http</Export-Package>
<Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.8</version>
<configuration>
<message>Generated site for ${project.name} ${project.version}</message>
<noJekyll>true</noJekyll>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>site</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.2</version>
<configuration>
<dependencyDetailsEnabled>true</dependencyDetailsEnabled>
<dependencyLocationsEnabled>true</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>sign</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<!-- Used to test proxy -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
There are several issues raised. Let me divide my answer.
Running builds as root
I highly recommend that you stop running builds as root.
[root#localhost http-request]# ls
lib pom.xml README.md
[root#localhost http-request]# cd lib
[root#localhost lib]# ls
pom.xml src target
This is a dangerous practice. Create a normal user account on your system and use this.
Dependencies missing in Eclipse
I have tested the project you are building and confirmed that it builds as follows:
git clone https://github.com/kevinsawicki/http-request.git
cd http-request
mvn install
You state that it fails when run from within Eclipse? Could this be because you have not installed the Eclipse plugin for Maven? See the following question:
How can I make eclipse make use of packages downloaded by maven?
No plugin found for prefix 'jetty'
This error is being thrown because the build has not been configured to use jetty. You need to read the documentation on how to enable this in your build
http://www.eclipse.org/jetty/documentation/current/maven-and-jetty.html
Your question here:
Google says I should add jetty plugins to mvn configuration .But I am confused about the project.Why doesn't the project developers add this to pom.xml?Or, there exist other solutions?
Needs to be addresses to the developer of the project. The most likely explanation is that he is not using Jetty to test his code. For example in my projects I use a continuous integration server (Jenkins) which automatically builds, deploys and tests code every time a code commit is made.

Packaging WAR with Java and Scala sources

I would like to ask you simple question. Is it possible to package WAR file which will contain Scala and Java sources, each from separate source directory (src/main/java/... and src/main/scala/...)? Of course, I still like to contain other resources like images and static pages into resulting WAR.
I've been looking into WAR plugin capabilities, regarding additional sources, but I didn't find anything helpful in this area. Can anyone give me a hint, where should I look for solution, or perhaps any kind of help?
Thanks,
Matthew
Here is a cut down version of the pom I use for my multi-language projects.
<?xml version="1.0" encoding="UTF-8"?>
<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.sksamuel</groupId>
<artifactId>test</artifactId>
<version>0.33-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.plugin.jar.version>2.4</maven.plugin.jar.version>
<maven.plugin.war.version>2.3</maven.plugin.war.version>
<maven.plugin.resources.version>2.6</maven.plugin.resources.version>
<maven.plugin.compiler.version>3.1</maven.plugin.compiler.version>
<maven.plugin.surefire.version>2.14.1</maven.plugin.surefire.version>
<maven.plugin.dependency.version>2.4</maven.plugin.dependency.version>
<maven.plugin.scala.version>3.1.5</maven.plugin.scala.version>
<compiler.version.source>1.7</compiler.version.source>
<compiler.version.target>1.7</compiler.version.target>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.plugin.war.version}</version>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${maven.plugin.scala.version}</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
After running mvn clean package inside that directory, with a scala source in src/main/scala and a java source file in src/main/java this is what I get. And as you can see the scala and java files have both been compiled into the war.
$ find .
.
./pom.xml
./target
./target/test
./target/test/WEB-INF
./target/test/WEB-INF/lib
./target/test/WEB-INF/lib/scala-library-2.10.2.jar
./target/test/WEB-INF/classes
./target/test/WEB-INF/classes/ILoveJava.class
./target/test/WEB-INF/classes/ILoveScala$.class
./target/test/WEB-INF/classes/ILoveScala.class
./target/test/WEB-INF/web.xml
./target/test/META-INF
./target/classes.-1172594870.timestamp
./target/maven-archiver
./target/maven-archiver/pom.properties
./target/test.war
./target/classes
./target/classes/ILoveJava.class
./target/classes/ILoveScala$.class
./target/classes/ILoveScala.class
./target/surefire
./src
./src/main
./src/main/webapp
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/web.xml
./src/main/java
./src/main/java/ILoveJava.java
./src/main/scala
./src/main/scala/ilovescala.scala