Unable to get external class files of scala in build jar eclipse - scala

I'm trying to create a runnable jar from scala spark project which consumes redis library. So, I created classes from Scala-Redis github project and used the package in my present code. The project builds and runs through eclipse interface but When I try to create jar - I receive classNotfound exception. On checking it was noticed that redis class was not included in build jar. I'm using other external jars as well. They are included in build but not the redis one. Where I'm going wrong or missing ?
Pom.xml is :-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>package-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.spark.ReCalculateOdo</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
I've included the class folder in build path run configurations. Suggestions please, Thanks,

I tried one trick and it worked. I don't know why this happens but its working for my case. So the idea is whenever you want a jar just clean build the project then run the project in eclipse now create maven install. You will find a jar in target folder of project. So , now you can use it with command line. It'll work.
Thanks,

Related

Having only a JAR Maven Archetype file, how can it be generated a new project?

I'm just starting with Maven 3 for an Scala project in IntelliJ.
I have generated a JAR file following this guide.
I moved archetype.jar to a directory in where I want to create a new project. But my questions are:
Is this file stand-alone? Is it enough? It does not work with the command "mvn archetype:generate"
Is it possible to use the jar file without the intervention of any repository? So I can share it with collegues.
What's the best method for this, I've been reseaching and all the guides are based on repositories only and not in working local. Even the local repositories only consists in xmls files with the id but not the contents.
This is a sort of complex question you are asking...I am going to try summarise what I know and let's see if it helps.
Answers to your questions:
1) If you have just the basic Maven Project structure after you have generated the archtype and so on, if you run maven clean install and the project produces a jar, this in theory should be immediately executable from the command line and standalone.
However, as you add dependencies to your small projects, not all dependencies are automatically built into the standalone jar, sometimes you have to tell maven to bundle them into it.
Maven Shade Plugin - adds all the needed dependencies into your jar
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MainApp</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
</plugin>
</plugins>
</build>
2) You do not need to integrate to any repository, its recommended for wider projects so that you can publish artifacts to your firms Repo for eas of use between developers
3) The easiest method is to create a new project in Intellij itself specifying Maven as the project type and that will give you the default project structure. In the pom file you then specify the build block I pasted above and you are essentially good to go...If you need Dependencies also t run your own code you will need to add them in a Dependencies block.
So, I finally used the following command before generating:
mvn install:install-file -Dfile=<path-to-jar-archetype-file> -DgroupId=<groupId> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=jar
After executing the command, the jar is installed in your local repo. You can generate the project with for instance IntelliJ or go to the path where you want to generate the project and...
mvn archetype:generate

How to tell Maven to update manifest's Bundle-Version?

I'm building Eclipse's plugins using Maven, and I'm looking for a way to tell Maven to update the Bundle-Version in the META-INF\MANIFEST.MF file.
The trick is, I need a clean way to do it. So that further colleagues (or even me in some months/years) may not break the final automated build.
Here is what I tried :
Using "Bundle-Version: ${project.version}" in the MANIFEST.MF
On a maven point-of-view, this is working.
BUT my Eclipse project is constantly displaying an error : The specified version does not have the correct format (major.minor.micro.qualifier)
Using the above but in another META-INF folder (named META-INF-MAVEN) that is used by maven instead of the original :
<resources>
<resource>
<directory>META-INF-MAVEN</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
</resource>
</resources>
This is still "working", but the needed duplication of MANIFEST.MF file is far away from what I'm looking for. This is a large trap for future errors, like editing the original MANIFEST.MF file and forgetting the maven one, resulting in a bugged release.
Using org.apache.maven.plugins to add the Bundle-Version tag at compile-time from the pom file :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>target/classes/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Bundle-Version>${project.version}</Bundle-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
This is the most promising way, BUT it only works if the original MANIFEST.MF does not have a Bundle-Version line.
The result is, again, an error within the Eclipse project.
And so, here I am, asking for any idea.
Thanks.
Following solution finds the Bundle-Version: line in META-INF/MANIFEST.MF and replaces it with the Maven project version. replacer maven plugin was used for that but there are certainly other maven plugins that can do the same work like find-and-replace-maven-plugin.
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>update-manifest-version</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>${basedir}/META-INF/MANIFEST.MF</file>
<regex>true</regex>
<replacements>
<replacement>
<token>Bundle-Version: .*</token>
<value>Bundle-Version: ${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion}.${project.artifact.selectedVersion.incrementalVersion}.qualifier
</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>

How to generate second EAR with sources

I have a project that consist of multiple modules (ejb's, jar's, war's) and I'm using a pom.xml of type "ear" to package them. It works perfectly fine and it generates an EAR-file with the correct jar's / etc.
What I additionally need is a second EAR-file with source code of included modules... I tried to use the source plugin as follow but the generated EAR didn't include any sources:
<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>
Funnily enough when I run "install" on my parent pom.xml, where all modules are included, the %MODULE_NAME%-sources.jar files are generated in my local maven repository. Is it possible to somehow reuse them and package into a second EAR?

How to copy dependencies to gae war/WEB-INF/lib

I'm coming from Ant perspective, so pardon me. I realise there are quite a few questions here already on how to maven dependencies, but none of them seem to tell how to do what need to do.
Question 1:
Currently, in conjunction with using maven-war-plugin, when I run mvn war:war, it creates a war folder in target folder.
However, I wish copy all the dependencies' jars to war/WEB-INF/lib set up by google eclipse plugin (with gae enabled, gwt disabled), without overwriting the jars that google eclipse plugin placed there.
I don't wish to setup a war file or war directory. I just need to copy/consolidate all the non-gae jars with the gae jars so that when the project is run as a gae web app, Eclipse would not complain ClassNotFoundException.
Question 2:
When using Ant in Eclipse, I could run Ant targets within Eclipse.
Right now, I have to perform mvn commands from a shell window (which is mutually oblivious to the existence of an Eclipse session). It appears that the only thing that is automatically done is whenever I update dependencies.
Is there a way, or any plugin for eclipse that would allow me to run mvn goals within Eclipse?
Additional info:
mvn dependency:copy-dependencies persists in copying to target/dependency directory, with the following:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
I even tried changing to absolute path
<outputDirectory>
/home/geek/eclipse/workspace/Demo-autoshoppe/holycow
</outputDirectory>
But holycow directory is still empty and mvn still persists in copying to target/dependency directory. My current solution is to softlink target/dependency as war/WEB-INF/lib, which is a very very bad kludge. Why is maven not sensitive to outputDirectory specification? I am using Ubuntu's maven 2.2.
I have the real answer for you, my man.
Use the "default-cli" execution id. Make sure you're using Maven 2.2+. This exec-id applies to command-line executions of the mojo.
<build>
<pluginManagement>
<plugins>
<!-- Copy dependencies to war/WEB-INF/lib for GAE proj compliance. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
Cheers.
An associate emailed me this answer which works. Trigger the follow through
mvn build or mvn package
but not directly thro mvn dependency:copy-dependencies.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
Regarding #1: I'd suggest creating your maven project based off this plugin and archetype http://code.google.com/p/maven-gae-plugin/ (see the GWT based example if you are writing a GWT app for GAE).
Regarding #2: Check out m2eclipse plugin for full maven integration in eclipse. It's written by Sonatype (the creators of maven): http://m2eclipse.sonatype.org/

How to setup bundle development environment (Eclipse Equinox Maven)

I'am trying to setup eclipse environment to develop bundles (With maven-bundle-plugin-bnd)
and run & debug that bundles equinox from eclipse
I created sample bundles with org.apache.felix maven-bundle-plugin and can install and start that bundles from eclipse equinox,
but every time i need to run "install file:C:\path\bundle1.jar","install file:C:\path\bundle2.jar" which causes pain. i searched for run configuration but it only intalls and starts (plugin) projects in workspace not maven projects.
What i have done is create maven project and add dependencies(bundle1,bundle2 etc..) and added maven-dependency-plugin to copy all depended bundles in one folder (another problem is equinox use "_" delimeter to determine version of bundles but maven uses "-" as delimeter) if i do not strip version in standalone equinox application i need to give version of bundle in config.ini file but i dont want that, is this proper way to solve this problem?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${bundleDirectory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
To sum up , i have bundles in folder, which is created with org.apache.felix maven-bundle-plugin , how can i run and debug them from eclipse?
I wouldn't say this is a "proper" solution, but it may work for you.
The antrun plugin can be used to modify the dependencies to replace the final hyphen with an underscore, so the dependency plugin doesn't need to strip the version.
My regex is rusty, but from a little testing the following configuration appears to apply the required name change to the files in the bundleDependency directory.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${bundleDirectory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- move within same directory is preferred method for a rename-->
<move todir="${bundleDirectory}">
<fileset dir="${bundleDirectory}"/>
<mapper type="regexp" from="([a-zA-Z0-9\.-]+)(-)([0-9\.]+.jar)"
to="\1_\3"/>
</move>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
I wrote a tool called auto-builder (http://code.google.com/p/auto-builder). It introspects PDE-based projects and generates Ant build files; it supports transitive closure over dependencies and all that jazz.
I posted a write-up: http://empty-set.net/?p=9. I wrote it because the Maven tools I played with, when integrated with PDE, didn’t “just work.” Basically, I wanted to do coding in PDE and have a Hudson-based CI without any fuss in between.
Generating Ant files is nice because it gives you all the benefits of a declarative build tool, but it leaves you with a procedural description of what it is doing.
I am looking for more PDE-based projects to test it on. There are a couple RFC-0112 Bundle repositories around, and I have some code for downloading dependencies. If anyone is interested, then I could integrate dependencies download with auto-builder.