Wildfly Deployment Issue- dependency resolution - deployment

I have a jar and a war file.
jar file is say x.jar and war file is y.war.
I have a jboss-deployment-structure.xml which specifies that y.war is dependent on x.jar.
Now I want these two files to be deployed in the following sequence x.jar followed by y.war.
I have a class in y module which is annotated with #Startup, which uses a class of x module and fails.
Please let me know how to solve this issue.

Related

No EJB found with interface when built as jar

I have the following error when deploying and starting the application with Wildfly.
No EJB found with interface of type "de.dev.java.project.api.ProjectApi" for binding de.dev.java.project.restservice.ProjectRestService/projectApi.
Project module structure:
- project-api -> built as jar
- ProjectApi.java
- project-impl -> built as jar
- ProjectRestService.java
{
#EJB ProjectApi projectApi
}
- application -> built as ear, which includes modules above
I only have a problem when i build "project-impl" module as jar. When i built as war i do not have a problem. What does war include which jar does not?
You must build as a proper ejb jar, not just regular jar. It also needs to be referenced properly in the ear. Use you IDE to setup suitable maven project with the right archetype

how to package and reference text file in resources folder

I have a spark project using scala and sbt. At one point it references a text file which I want to be packaged.
This is how it is referenced in the application source:
getClass.getResource("/myFile.txt")
This works fine running the source code with sbt run. But I want it to be packaged and deployed to a server.
In build.sbt, after some googling I have got this to work
import NativePackagerHelper._
mappings in Universal ++= directory("src/main/resources")
adding this meant that the myFile.txt appears in the resources folder in the package. created using
sbt universal:packageBin
resulting folder structure:
target - universal - bin
- lib
- resources
however when I run my packaged application from bin/my-application.bat , I get the following error
Exception in thread "main" org.apache.spark.sql.AnalysisException: Path does not exist: file:/C:/Software/my-application-0.0.1/lib/my-application-0.0.1.jar!/myFile.txt;
Bear in mind I have zero experience of deploying scala or jvm based things so you may have to spoonfeed me the explanation
EDIT I later realised that the text file was in fact included in the .jar file.
the issue then was that getResource does not work in this case and I had to adapt my code to use getResourceAsStream
This can have multiple reasons.
Include files in your resulting jar
You added this line, which is not correct
import NativePackagerHelper._
mappings in Universal ++= directory("src/main/resources")
The src/main/resources directory is the resourceDirectory in Compile and the contents are always present in the package jar file (not the zip!). So I would highly recommend removing this snippet as you will have your files twice in your classpath.
The mappings in Universal (documentation link) define the content of the created package (with universal:packageBin the zip file). I assume that you are using the JavaAppPackaging plugin, which configures your entire build. By default all dependencies and your actual build artifact end up in the libs folder. Start scripts are being place in bin.
The start scripts also create a valid classpath, which includes all libraries in lib and nothing else by default.
TL;DR You simply put your files in src/main/resources and they will be available on the classpath.
How to find files on the classpath
You posted this snippet
getClass.getResource("/myFile.txt")
This will lookup a file called myFile.txt in the roots of your classpath. As in the comment suggested you should open your application jar file and find a text file myFile.txt at the root, otherwise it won't be found.
hope that helps,
Muki

Trouble running jar file created by Eclipse

I exported my Eclipse project as a runnable Jar file, added a manifest, as well as the appropriate class files with the command:
jar cfm JarFile.jar manifest.txt *.class
However, when I try to run the jar file with
java -jar JarFile.jar
I get the error that it "Could not find or load main class" etc. etc.
The structure of my manifest.txt file looks like this:
Main-Class: EclipseProjectName.src.packagename.mainclassname
(With a carriage return at the end)
Is something wrong with my manifest file? If not, what may be the reason that the main class cannot be found?
Thank you!
The manifest file extension should be .mf i.e manifest.mf. See here for jar file specification
Suggest to use fat jar eclipse plugin for exporting java projects as runnable jars.
Edit
Correct the content of manifest.txt as shown below
Main-Class: EclipseProjectName.src.packagename.mainclassname
project name and src are not required. Refer this
The entry in the META-INF/MANIFEST.MF entry in the finished jar file should be
Main-Class: packagename.mainclassname
and should correspond exactly to
/packagename/mainclassname.class
in your jar file (or jar file_s_ if you use Class-Path too).

JAR inter-dependencies inside WAR with ant

We have to package (using ant) a war file to be deployed (on tomcat )
Inside the lib folders, there are several jar files:
3rd-party-lib-A.jar
3rd-party-lib-B.jar
3rd-party-lib-C.jar
...etc
Such that lib-A depends on lib-B ...etc
The WAR is deployed fine, but cannot be started because errors likes this happen:
INFO: ExtensionValidator[/MyWebApp][3rd-party-lib-A.jar]: Required extension "lib-B" not found
INFO: ExtensionValidator[/MyWebApp][3rd-party-lib-A.jar]: Required extension "lib-C" not found
..etc
inside the manifest file of "3rd-party-lib-A.jar" we can find:
...
lib-B-Extension-Name: lib-B
lib-B-Implementation-Version: 1.1
lib-B-Implementation-URL: http://10.10.1.148/bundle/3rd-party-lib-B.jar
log4j-Extension-Name: log4j
log4j-Implementation-Version: 1.2.9
log4j-Implementation-URL: http://jakarta.apache.org/log4j
...
My question is, how to go from here?
1) repackage each jar to have a manifest with class-path, using relative path?
2) put the jars in the tomcat lib?
3) read the manual? :)
4) use maven?
thanks

SBT exclude scala-library.jar from a war file packaged using xsbt-web-plugin

I have a project that only needs to take a proguard-constructed jar file, which is built in a separate SBT project and contains all classes needed to run as a servlet, and create a war file out of it.
The dependency is properly packaged into the war, and the transitive jars are excluded correctly using notTransitive(), but scala-library.jar continues to be placed into the war file as well. This is not desired, since the proguard-built jar contains those scala classes that are necessary for the servlet filter to run. The present project just needs to take that dependent jar, add a web.xml, and package it into a war file.
What is the simplest way (preferably using a build.sbt file) to get the war packaging mechanism from the xsbt-web-plugin to exclude the scala-library.jar?
This should work, it .sbt:
autoScalaLibrary := false