Errors deploying Java + Groovy mixed code on Heroku - java

I'm trying to deploy a project on Heroku but I'm getting Maven compilaton errors like this:
remote: [ERROR] /tmp/build_5d64555c50abcb9638e3ef5b331a0107/src/main/java/com/davioooh/myapp/services/TestService.java:[3,43] package com.davioooh.myapp.domain does not exist
In my project I'm using both Java and Groovy classes. All Groovy classes are in com.davioooh.myapp.domain that can't be found during compilation.
I also tried to move all Groovy classe in src/main/groovy folder but it's still not working...
Is there a way to correctly deploy my application?

I finally solved adding Groovy Eclipse Maven Plugin as compiler plugin in my project pom.xml.
<build>
...
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.3.7-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
...
</build>

Related

JDK sources in Eclipse using maven

I have some Maven projects that I develop under Eclipse. When I want to see the source of a third party class, if the sources were published, I can simply read them:
However when I try to do the same with any of the default classes, those that are part of the JDK, I see a "Source not found" screen:
One of my pom.xml contains this:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
I was looking for a way to put the JDK in as a dependency, but I can't find a clue, how. I'm not even sure, if that would solve the problem, because my project compiles fine. I also am also aware that I can simply attach the sources through Eclipse, but again I'm not sure, if that would be a nice solution, as Maven can download the other sources.
Do you have any idea what could cause this, and how to solve the problem?

Spark related jars cannot be resolved in Eclipse

I'm new to Spark so am trying to setup a project from the book Learning Spark: Lightning-Fast Big Data Analysis. The book uses version 1.3 but I've only got 2.1.1 so am trying to work around a few differences.
All the Spark related jars that I'm importing into my Java project have a "import org.apache cannot be resolved". I know it's because the project cannot find the jar files specified.
I can manually add each by going to Build Path > Configure Build path and adding them to the Libraries section but I think I shouldn't need to do this. The project uses Maven so I believe if I have the Spark dependencies configured correctly in my pom.xml it should work. Is this correct?
I also set the following environment variables:
export SPARK_HOME=/Users/mymac/spark-2.1.1-bin-hadoop2.7/
export PATH="$SPARK_HOME/bin/:$PATH"
Are there any others I should be aware of?
Here's the contents of my pom.xml:
<project>
<groupId>com.oreilly.learningsparkexamples.mini</groupId>
<artifactId>learning-spark-mini-example</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>example</name>
<packaging>jar</packaging>
<version>0.0.1</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
This should be setup as a Maven project, not a Java project. In my case to resolve deleted the project from my workspace, re-created it in the workspace as a general project, then converted it to a Maven project. I probably should have just set it up as a Maven project at the start.

How do get content-assist working for groovy in eclipse

I am trying to build a groovy+java+maven project in Eclipse. New to setting up groovy with Eclipse so I am possibly missing out a bunch installations. I did the following thus far -
Downloaded Groovy Eclipse and Groovy Eclipse M2E version 2.9.1 (Followed this page - http://www.vogella.com/tutorials/Groovy/article.html)
My pom has these -
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.3.7</version>
</dependency>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.1-01</version>
<!-- extensions>true</extensions -->
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.3.7-01</version>
</dependency>
</dependencies>
</plugin>
</plugins>
I can't seem to get any content assist in my groovy class under src/main/groovy. I tried using some of the java.util classes like Collection. I am able to get content assist as usual for java classes in src/main/java.
Under Prefereces > Java > Editor > Content Assist > Advanced "Groovy Content" is checked.
So what am I missing? Thanks in advance for your suggestions.

Maven: Missing dependency when using test-jar at runtime

My Maven project foo.web has its source files in src/main and the test sources in src/test. Of course, the test classes make use of the "main" classes. Now I want to use the test classes in another project during runtime, so I followed these instructions on how to create a test-jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
This works perfectly well, a jar like web-SNAPSHOT-tests.jar is created and I can include it in my other project.
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>test-jar</type>
</dependency>
But it seems like the dependency to web-SNAPSHOT is not correctly set, because at runtime I receive NoClassDefFoundErrors of classes which are available in foo.web. So I added another dependency:
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
Unfortunately, this changes nothing. Does anyone know what is wrong here?
WAR archives are structured differently from JARs. When running in an application server such as Tomcat or JBoss, the server will handle the WAR correctly. Since you are running outside of a server, the artifact will be used like to a normal JAR archive. Because WARs use different locations for the .class files, the NoClassDefFoundError is thrown at run time.
In a JAR, the class com.example.Foo will be stored at /com/example/Foo.class. Since WARs are designed to contain libraries, resources etc. the classes should not be stored relative to the root of the archive. Instead, they are contained in the folder /WEB-INF/classes, Foo would be stored as /WEB-INF/classes/com/example/Foo.class.
Fortunately, the Maven developers thought of this issue and added the attachClasses option to the WAR plugin. This option creates an additional JAR with the classes classifier that contains only the Java classes in JAR format (relative the the archive root).
To enable the building of this JAR, you can use this snippet in your WAR project's build section (in addition to the configuration for the maven-jar-plugin to build the test JAR):
<pluginManagement>
<plugins>
<!-- … -->
<plugin>
<!-- build the classes JAR (non-test classes) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- … -->
<plugin>
<!-- build the test JAR (test classes) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Since the classes are attached, they will be installed and deployed by Maven together with the WAR artifact. Note that this only provides you with the contents of the regular WAR archive, to use the test classes, you need to depend on both the classes artifact and the test jar. To do this, you can use:
<dependencies>
<!-- … -->
<dependency>
<!-- test classes only -->
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>test-jar</type>
</dependency>
<dependency>
<!-- non-test classes only -->
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>jar</type>
<classifier>classes</classifier>
<scope>runtime</scope>
</dependency>
</dependencies>
Try:
<dependency>
<groupId>foo</groupId>
<artifactId>web</artifactId>
<version>SNAPSHOT</version>
<type>war</type>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Maven allows you some configuration regarding snapshots dependancy
<repository>
<id>foo-repository</id>
<url>...</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>XXX</updatePolicy>
</snapshots>
Check the above config. If its false in pom.xml maven will not update snapshots. Also you will find the following thread useful for your query What exactly is a Maven Snapshot and why do we need it?

Converting Maven project to EAR

I am new to maven.
I have created a maven project , in this i have twosession beans and i have added all dependencies in pom.xml. I want to conver this project to EARso that I can deploy it on jboss EAP 6.0 .
I have used
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
but it doen't provide the runtime dependencies.
How do i convert maven project to EAR file. How do get all dependencies including project dependencies at runtime.
I would suggest using maven-ear-plugin. The pom.xml would have the following item inside <build><plugins>..</plugins>..</build> listing:
(taken from the documentation)
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<!-- configuration elements go here -->
</configuration>
</plugin>
</plugins>
</build>
Please also refer to the documentation here: http://maven.apache.org/plugins/maven-ear-plugin/usage.html.
Maven handles all the dependencies that you list in the <dependencies>...</dependencies> section that follows the above block. For example:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
You can get the dependency details, like the above for log4j, from various maven repositories online. (http://search.maven.org/, http://mvnrepository.com/ etc.)

Categories

Resources