Where is deployed content for JBoss AS 7 - jboss

I am new to JBoss AS 7. I have tried to deploy my war file on JBoss AS 7, which seems working fine. My question is where I can see the deployed content.
I would expect it to be like Tomcat, it should have a explored war folder some where to hold the deployed content. Is there such thing for JBoss AS 7.

It should be in JBOSS_HOME/standalone/deployments see there
If you deploy a war file name as 'sample' then you could see this file domain/configuration/domain.xml as
[...]
<deployments>
<deployment name="sample.war"
runtime-name="sample.war">
<content sha1="dda9881fa7811b22f1424b4c5acccb13c71202bd"/>
</deployment>
</deployments>
[...]
<server-groups>
<server-group name="main-server-group" profile="default">
[...]
<deployments>
<deployment name="sample.war" runtime-name="sample.war"/>
</deployments>
</server-group>
</server-groups>
[...]
ls domain/content/
|---/47
|-----95cc29338b5049e238941231b36b3946952991
|---/dd
|-----a9881fa7811b22f1424b4c5acccb13c71202bd
This works for standalone/content as well.
Note that in the standalone.xml file, as referenced above, the sample.war file has a hash. The hash is the key to locating the WAR file. You will not find it by searching for "sample.war" in the 'content' directory though. First 2 characters of hash is parent directory. The rest is the directory containing the WAR file. However the WAR file has been renamed to 'content'
|---/47
|-----95cc29338b5049e238941231b36b3946952991
|---/dd
|-----a9881fa7811b22f1424b4c5acccb13c71202bd
|-------content <-- this is really sample.war file. JBoss renames it. (go figure!)
do a jar -xvf content and you will see all the class, web.xml, etc files for sample.war

Alternative way to deploy: maven-jboss-as-plugin.
You simply run
mvn deploy
And it deploys your war.

you can find your deployed jars here:
$JBOSS_HOME/standalone/tmp/vfs/deployment/

Related

How to configure a standard path in a container created by Jib

I have a standard Sprinb Boot project.
And in the folder: src/main/resources/tmp/my_file.json, i have a json that I read in my Java code.
File file = new File("src/main/resources/tmp/my_file.json");
When running it locally it goes perfectly
With Jib I create a docker image:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<from>
<image>adoptopenjdk:11-jre-hotspot</image>
</from>
<to>
<image>xxx/my_project:${version}</image>
</to>
<container>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
</configuration>
</plugin>
When I run the container, it gives me an error that it cannot find the file:
java.io.FileNotFoundException: src/main/resources/tmp/my_file.json (No such file or directory)
The "src/main/resources" folder is the standard location for static resources.
Should I add any extra configuration to Jib to make the file available?
You don't want your application to open a file based on the source project structure. At runtime (whether packaged as a JAR file or a container image), you won't have the src/ directory, and new File("src/...") will always fail. For example, even outside the Docker context, suppose you packaged your app as a runnable jar. Then running your app with java -jar <your-runnable.jar> will fail from the same error.
What Java folks usually do is to search files on a classpath, and this is pretty much the standard way to what you're trying to achieve. You can find many useful materials when you google "java get resources", but here are some references:
https://www.baeldung.com/java-classpath-resource-cannot-be-opened
https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html
https://mkyong.com/java/java-read-a-file-from-resources-folder/
As of now, Jib 2.7.0 is the latest.
The problem is not with Jib but with your code.
Put "src/main/resources/" on the class path -- this is a standard way. And modify your code as below:
File file = new File("tmp/my_file.json");
When Jib creates an image, it copies all the resources from "src/main/resources/" to a directory ("/app/resources") on the image and puts that directory on the class path while launching your application.

How do I get an EAR to read a properties file from a WAR?

I'm using Wildfly 11 and Java 8. I'm trying to deploy an EAR file that contains multiple WAR files. One of my WAR files contains this in its web.xml ...
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>csrfguard.properties</param-value>
</context-param>
The file in question is within one of my WARs at
myapp.war/WEB-INF/classes/csrfguard.properties
When I deploy the WAR by itself, everything deploys fine. However when I deploy the EAR containing the WAR I get an error complaining about not being able to locate the properties file ...
Caused by: java.io.IOException: unable to locate resource - csrfguard.properties
at org.owasp.csrfguard.CsrfGuardServletContextListener.getResourceStream(CsrfGuardServletContextListener.java:85)
at org.owasp.csrfguard.CsrfGuardServletContextListener.contextInitialized(CsrfGuardServletContextListener.java:36)
... 10 more
I sense that there is a class loader issue happening that I'm not figuring out how to work-around. How do I tell my EAR file where to find the properties file in question?
I suspect that the wrong class loader is being used to search the classpath for csrfguard.properties, which would cause getResourceAsStream to fail. In the .ear file, where does the CSRFGuard library get packaged?
You can try using the context.getRealPath fallback by switching to a path relative to the .war file:
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>WEB-INF/classes/csrfguard.properties</param-value>
</context-param>
I had the same problem. Fixed it by adding the csrfguard.jar inside the WEB-INF/lib directory of the WAR file and not the lib directory of the EAR. Added the csrfguard.properties file to WEB-INF/classes directory and used the following context param in the web.xml
<context-param>
<param-name>Owasp.CsrfGuard.Config</param-name>
<param-value>csrfguard.properties</param-value>
</context-param>

Reference a jar file in the persistence.xml within a Spring Boot project [duplicate]

persistence.xml looks like this:
<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>jdbc/test</non-jta-data-source>
<jar-file>../../lib/app-services-1.0.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
It is a web project, so the deployment unit is a war file.
The jar file I tried to refer is in WEB-INF/lib/ folder , persistence.xml is in WEB-INF/classes/META-INF folder. When being deployed, it simply tells me
"WARNING: Unable to find file (ignored): file:.../../lib/app-services-1.0.jar".
I also tried every possible path I could think of, i.e. ../lib/app-services-1.0.jar, lib/app-services-1.0.jar.
What is the right path to do this?
Taking a look at jsr always works!
8.2.1.6.3 Jar Files
One or more JAR files may be specified using the jar-file elements instead of, or in addition to the mapping files specified in the mapping-file elements. If specified, these JAR files will >be searched for managed persistence classes, and any mapping metadata annotations found on them will be pro-cessed, or they will be mapped using the mapping annotation defaults defined by this specification.
Such JAR files are specified relative to the directory or jar file that contains the root of the persis-tence unit.
The following examples illustrate the use of the jar-file element to reference additional persistence classes. These examples use the convention that a jar file with a name terminating in “PUnit” contains the persistence.xml file and that a jar file with a name terminating in “Entities” contains additional persistence classes.
Example 1:
app.ear
lib/earEntities.jar
earRootPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 2:
app.ear
lib/earEntities.jar
lib/earLibPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>earEntities.jar</jar-file>
Example 3:
app.ear
lib/earEntities.jar
ejbjar.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>lib/earEntities.jar</jar-file>
Example 4:
app.ear
war1.war
WEB-INF/lib/warEntities.jar
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>warEntities.jar</jar-file>
Example 5:
app.ear
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
Example 6:
app.ear
lib/earEntities.jar
war2.war
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>../../lib/earEntities.jar</jar-file>
Example 7:
app.ear
lib/earEntities.jar
war1.war
WEB-INF/lib/warPUnit.jar (with META-INF/persistence.xml )
persistence.xml contains:
<jar-file>../../../lib/earEntities.jar</jar-file>
As you see there is no example for war files, all war files in the examples above are inside ear files!
But I tested in war files and it works just when I specify the absolute path of jar files and it is not a good approach for production environment!
just in case someone else stumbles upon this: the jar-file-statement is only valid. when the persistence-unit is deployed as part of an Enterprise Archives (.ear) - in every other case (.war), the persistence.xml must reside in /META-INF/ and cannot refrence classes that live outside the persistence-unit (see: http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html). So, as far as I know, there is no way to have a persistence.xml living in WEB-INF/classes/META-INF that references classes that do not live in WEB-INF/classes.
war2.war
WEB-INF/lib/warEntities.jar
WEB-INF/classes/META-INF/persistence.xml
persistence.xml contains:
<jar-file>lib/warEntities.jar</jar-file>
this format works for war file. Im using Wildlfy 8.2.0 and JPA 2.1
Not sure this is related to the fact that you are deploying as a WAR, but the path should be simply "app-sevices-1.0.jar" and the jar should be in the lib of the Java EE application. The thing is: I'm not sure if this is available for the simplified "war" Java EE application. I suspect this is available only for the traditional Java EE deployment file (ear). I would test making an EAR, containing a WAR for the webapp, JAR for the PU and your other JAR for app-services, like a traditional Java EE deployment would be.
Another thing to note is that relative paths are not supported, and usage of this in SE environment is not supported by all vendors.

Injecting beans into filter packaged in a shared library

I've got an JavaEE6 app with following structure:
app.ear
META-INF
application.xml
lib
commmon-server-lib.jar
webapp1.war
webapp2.war
services-ejb.jar
Both webapps have common-server-lib.jar in Class-Path entry of their MANIFEST.MF (skinny war's).
application.xml:
<application>
<module>
<ejb>services-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>webapp1.war</web-uri>
<context-root>/webapp1</context-root>
</web>
</module>
<module>
<web>
<web-uri>webapp2.war</web-uri>
<context-root>/webapp2</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
In common-server-lib.jar there is a web filter that should have few EJBs and other CDI managed beans injected. This filter is defined in web.xml's of both webapps.
common-server-lib.jar and war's have beans.xml in appropriate place.
Now the problem is, that when I try to deploy this app to Glassfish I get errors like this:
Class [ Lcom/acme/UserService; ] not found. Error while loading
[ class com.acme.filter.MyFilter ]
UserService service is located in services-ejb.jar
So my question is: what am I doing wrong...? Is there something wrong in defining web components (that use injections for it's dependencies) in a shared library?
Edit:
In section 15.5 of JSR-315 (Servlets 3.0 final spec) one can find:
In a web application, classes using resource injection will have their annotations
processed only if they are located in the WEB-INF/classes directory, or if they are
packaged in a jar file located in WEB-INF/lib.
I've moved common-server-lib.jar to WEB-INF/lib directories of both webapps but I'm still having same issue ;/...
After many hours of struggling with this puzzle I've found a solution:
Add web-fragment.xml to commmon-server-lib.jar with my filter
Remove filter specification from webapps web.xml's
Change maven fonfiguration to remove all jar's from WEB-INF/lib
directory except commmon-server-lib.jar
Remove commmon-server-lib.jar from EAR /lib directory

Log4j2.xml file not being seen when using NetBeans

I'm having a problem with my logj2.xml being seen on my Windows7/64 box running Java 1.7.0_13/64. I'm trying to run the application using the NetBeans/64 7.2.1 IDE via the debugger.
log4j2.xml is sitting in my r:\ directory. The (user)classpath is ".;r:\". It is apparently not being seen, because when I look at the 'config.config.name' of the Logger in my debugger, it gives me the value of 'Default'. Also, I can't find the file specified in the log4j2.xml file anywhere, on any drive, of my machine. I've also looked for any new files containing the word 'default' on my machine, and can find none that are current.
So I suspect I'm doing 1 of 2 things wrong:
1) Setting my classpath incorrectly.
2) Putting my log4j2.xml file together incorrectly.
Any help would be appreciated. My keys are getting sticky from banging them with my forehead.
Here's the config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug" name="xxx" packages="" >
<appenders>
<RollingFile name="log" fileName="qqq.log"
immediateFlush="true" filePattern="qqq-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>"%d{YYYY-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %n%msg%n%n%n"</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy />
</Policies>
<DefaultRolloverStrategy max="92"/>
</RollingFile>
</appenders>
<loggers>
<root level="trace">
<appender-ref ref="log"/>
</root>
</loggers>
</configuration>
Ok, got it. I've renamed this question to include NetBeans, because that was the gist of my problem.
As a review, it is required that the log4j2.xml file needs to go on the classpath. While I could affect the classpath in netbeans by adding jar files to the project, I didn't initially think about finding a config file on the classpath. Anyway, once I realized that, I played around a bit in project properties, and finally figured out that just adding the folder to the 'Compile-time libraries' dialog ( in this case "r:\" ) puts the config file on the classpath, and my logging works just like it should.
Whew!
Hope this helps someone.
Thanks joe7pak, your posts were the last piece of the puzzle to solve my log4j properties problem in NetBeans. My problem required a couple extra steps that may help round this solution out.
First, I created a log4j.xml file in the src directory using the default xml from http://wiki.apache.org/logging-log4j/Log4jXmlFormat.
I then set the NetBeans VM options in Properties\Run to: -Dlog4j.debug. I noticed that a jar's (httpbuilder) log4j.xml file was being loaded by default instead of mine.
So I added the src folder to the compile time libraries in Properties\Libraries using your recommendation. However, it was still loading the log4j.xml file from the jar.
The final touch was to move the src folder to the top of the compile time libraries.
Thanks for your post and for answering yourself.