Maven "Failed to create assembly" Problem - plugins

I use a very simple assembly desriptor:
<fileSets>
<fileSet>
<directory>domain/etc/scripts/</directory>
<outputDirectory>tools</outputDirectory>
<includes>
<include>*.bat</include>
</includes>
</fileSet>
</fileSets>
But I get all the time the following Error:
"Failed to create assembly: Error creating assembly archive test: You must set at least one file" I also get this message if I execute maven with -e
BUT! The files where transfered to the "tools" directory! I don't understand why I get an error but the files are in the directory... I use "mvn assembly:single" goal
Can somebody try to explain it :) I also use assembly Plugin in the other Module but it works pretty fine.

Related

Maven gives dependencies issues

I am using Eclipse 2020-06 (4.16.0) version.
In my application I have maven-compiler-plugin defined in my Pom.xml like below.
I also have the specific jars in /users/.m2/repository folder.
When I run the Maven on my project, I still get this error.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project <>: Compilation failure: Compilation failure:
Also I see the below error:
[ERROR] error reading C:\Users\XXXXXXX.m2\repository\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar; ZipFile invalid LOC header (bad signature)
I thought httpclient jar file and maven-compiler-plugin got corrupted. I downloaded from internet and did mvn install. Still I see these errors. How can we resolve it.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
In your .m2/repository tree, remove the entire "4.5.6" directory. In your project directory, rerun "mvn -U" package (-U is probably overkill after deleting the directory, but it's a good habit to get into, to ensure that dependencies are redownloaded). Verify that it shows Maven redownloading the httpclient artifact. If you still see the same error, look at the contents of the downloaded "httpclient-4.5.6.jar" file. In this case, I expect it will be a text file, containing html output. If so, that means there is something wrong with your proxy settings in your settings.xml file.

Preserving Manifest.mf when building via sbt assembly

When I build my project using sbt assembly, I get java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF. The solution that google recommends, is to use MergeStrategy.discard.
That works in getting the project to build - but it crashes at runtime, because Dropwizard (a dependency) relies on info contained in manifest.mf (full issue details: https://github.com/dropwizard/dropwizard/issues/455 ).
The recommendation when encountering that error, is to merge the manifests.
I've tried all the MergeStrategies on Manifest.MF that seem like they'd do the trick (filterDistinctLines, concat, first, last), they all cause the build to fail with java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF. The only thing that compiles is discard, but that causes the program to crash at runtime due to Dropwizard relying on the mf file.
Any ideas what to do here? Is there a way to merge the manifests as described in the comments at https://github.com/dropwizard/dropwizard/issues/455 ?
So I ended up doing this:
Separated the Scala & Java projects
Build the sbt project as is - copy it to the java project/lib directory
Added a system dep for lib/scala project, and used the add-jar plugin to add this jar to the classpath when building the fatjar:
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${real.base.dir}/lib</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Build the java project fatjar and deploy it - it now has access to the scala jar on the classpath.
Script (server is the name of the java project i made):
sbt clean assembly
cp target/scala*/project*.jar server/lib
cd server
mvn clean install
cd ../
cp server/target/server*.jar target

How to resolve the playN asset path error?

I am getting the following error when I run my playN project.
"No file found for: /myproject/myproject.nocache.js"
Also I am getting only a black screen in the browser.
In the MyProjectHtml.java file I am giving the path as
"platform.assets().setPathPrefix("myproject/");"
How can I resolve this problem. I am not finding any file with the name "nocache".
Note: The comment in one of my previous question's answer will be useful: How to Run my playN game in production mode locally?
Thank you.
SOLVED: the resource folder under war was getting generated using eclipse compile only.I have created a source folder src/main/resources and moved all my resources package to it. Before it was under src/main/java. Now it works..! I can compile from terminal and run.
Are you running the project via Maven (mvn test -Ptest-html) or as GWT project (mvn gwt:run)?
The first case should work if your path is set correctly, but running it as a GWT project has always failed for me.
I also suggest doing a mvn clean install, and seeing which resources are contained within your .war file. Your .nocache.js file should be in there, if not, you probably have a bigger issue (incorrect project setup).
Update:
Seeing as you don't have the .nocache.js file in your war something is wrong with your Maven configuration. See if the following config has been added to your HTML pom in your plugins tags:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
Either way, your HTML version won't run until you see the .nocache.js in your war file. Double-check your Maven configuration with a new PlayN project, and see where there are differences.

Mwe2Launcher - Couldn't find module

I constantly get:
mf.mwe2.launch.runtime.Mwe2Launcher - Couldn't find module x
error though the x.mwe2 file exists. I have enabled the xtext nature to the project and added related modules.
here's the .mwe2 file:
module com.ford.modelling.workflow.abcd
Workflow {
component = SayHello {
message = "hello"
}
}
What might be the problem? (a folder named src-gen already exists)
please make sure that the mwe2 file is placed in a java source folder and that you did a clean build on the project the mwe2 file is contained.
Had the same problem. The exception however occurs in the Mwe2Runner, not the Mwe2Launcher. The Mwe2Runner tried to load the mwe2 file as a resource and produces that error if it can't find it, although the Mwe2Launcher can.
Anyway, solution is to register your src-dir as a resource-dir by adding the following to your pom.xml
<build>
...
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
...
</build>
OK. I've found the problem (though not a solution yet).
Enabling scala nature halts the build process of MWE2. Can't figure out why but this is what happens. I remove the Scala nature and everything works.

deploying a maven project

I have a maven project and I'd like to create a distribution of it with the dependencies. I've tried the maven-assembly-plugin and built the jar with dependencies, but that unpacked all of the jars and repackaged them all into a big, single jar. What I'd like is something like my jar file and a lib folder that has all of the dependencies. Then when I run it, I could run "java -cp lib/* my.package.MainClass".
What's the best way to go about doing this with maven? Or the recommended way to deploy?
thanks,
Jeff
I have used the Maven assembly just for that in my project.
First enable your plugin in your POM and call your assembly config :
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<!--I recommend 2.1 as later versions have a bug that may
Duplicate files in your archive
-->
<version>2.1</version>
<!--Executes the packaging along with the mvn package phase
-->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<!--Relative path to your descriptor -->
<descriptor>src/main/assembly/package.xml
</descriptor>
</descriptors>
</configuration>
</plugin>
Then in your descriptor you can decide how you want your layout to be before you package the whole thing
<assembly>
<!-- this will create an extra resource project-1.1.1-package.zip, you can
choose jar as well in the format-->
<id>package</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<!-- Insert here extra files as configs or, batch files, resources, docs etc-->
<fileSets>
<fileSet>
<directory>src/main/assembly/files</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/conf/*.*</include>
<include>**/doc/*.*</include>
</includes>
</fileSet>
<!-- I like to integrate the jre as well... simplifies my deployement -->
<fileSet>
<directory>target/jre</directory>
<outputDirectory>/jre</outputDirectory>
</fileSet>
</fileSets>
<!-- This will scrub your dependencies and add them to your lib folder, I excluded
Test stuff as it is not needed, could have declared the resource as a test
only phase as well would not have had to exclude it here
-->
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
This will create a zip file with the layout you have specified in your output directory config, package the whole thing as a zip file (you can choose zip, jar, war ...) and deploy it in my repository with the rest.
I skipped bits and pieces to make it simpler but my package expands to include batch files, dlls, config, doc and the JRE so everything needed is in the same zip... all is needed to run the thing is extract and click start.bat !
I could also probably make it in to a jar properly formatted with METADATA and just double click the jar itself to start it all, I did not need or have time to toy around this option but you may try it as well.
Beware of versions above 2.1 of the assembly plugin, it will create duplicate entries if your directives enable it to find the same file in different locations, this will give you a lib folder with the same jars repeating twice. not very dangerous as unzipping will collapse them but still annoying to have the unzip ask you if you want to overwrite files. Plus the fact that you do not know which won if somehow they turned out to be different in content.
Maven is great but I find that it is sometimes frustrating to get it working, Plus documentation can sometimes be hard to find and use. However, used appropriately it will save you tons of time.
good luck
See:
http://maven.apache.org/shared/maven-archiver/index.html
You should be able to use the maven-jar plugin to package up an archive, specify the main class to execute along with the classpath. It can generate a manifest file for you for your project.
http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Prefix