Loading file from application .ear deployed on weblogic - java

I'm trying to write code that will load *.html file from application .ear and display it. The structure of my application is:
application
-src
-main
-java
-my.package.few.folders
-Class.java
-webapp
-my.html
I'm new in Java and weblogic so I'm not able to figure it out by myself and all threads I found in internet are mostly the same. File should be accessible using:
Class.class.getClassLoader().getResource("main/webapp/my.html");
The problem is that my application is deployed on weblogic and above code gives me path to a weblogic domain (not my application ear where are *.html files). So using this code I'm always getting null pointer exception because .ear is hidden inside few folders in weblogic domain. I want to avoid giving specified path to .ear in weblogic, because it need to work on different servers and with only managed server name changed it will crash. How can I get straight into my .ear, not through weblogic domain?

Related

GetResourceAsStream not working on Websphere server

Application Server : IBM Websphere
Java 6
Issue :
Below is the folder structure of web application :
WEB-INF/libs/props/
The issue is below code is not working :
this.getClass().getResourceAsStream('/props'/+fileName) where fileName is a valid file name inside props folder of WEB-INF/lib/pros.
The class which is calling above method is inside a JAR and included in lib
The above call returns NULL.
The same set up works on tomcat with web application deployed in expanded mode integrated inside Inteliij IDE. On environment where this issue is coming , the application is deployed as ear
Please help as I not able to get any clue on this
The jar files under WEB-INF/lib are in the classpath. Not WEB-INF/lib itself.
The file should be in one of those jars, or under WEB-INF/classes (which is in the classpath)

java.lang.NoClassDefFoundError: WEB-INF/classes/

I am getting an error when deploying an EAR file which contains a web service and a web application. I get a NoClassDefFoundError when I deploy the application because the server is looking in the wrong folder for the class file.
The server (WebLogic) thinks the class file should be in WEB-INF/classes, but it is in <project-root>/classes.
How do I change where WebLogic should look for class files? I already tried the classpath, doesn't work.
That is happening because this is the structure of the web application according to the specification. Check this out: https://docs.oracle.com/javaee/6/tutorial/doc/bnadx.html

Trying to access xml file in tomcat via URL, getting 404 error

I have a webapp deployed in Tomee+ 1.6.0 (tomcat 7.0). The app runs fine and I can access all pages. Within one of my app's folders (myapp/intructions/) I have placed a xml file that I will access via a client application.
The application will access the file for its configuration, and will be called via a batch file with the following command:
"C:\Java\jre7\bin\java" -cp MyApp.jar com.me.MyApplicationStart "argument1" "argument2"
Within MyApplicationStart the constructor tries to access the configuration from the URL
http://webserver:8080/myapp/instruction/myconfig.xml
As I have no control over the above methodology, this cannot be changed.
I would expect the xml to be downloaded (or fetched) and my application to work fine, but instead I get a 404 error. If I change the extension of my config file to .properties, everything works fine, but someone else other than me in the team insists that we use xml for the config file, since it will allow more automation features.
What gets me is why can't I access this xml (or any other) file from tomcat. It seems that in previous versions of tomcat this was not a problem, or at least not with files outside the WEB-INF folder. Now it is and it seems to be exclusive to xml files, which suggests that there's a configuration in place that prevents access to this extension from anywhere in the webapp.
Would anybody know what this configuration is, or what is the mechanics behind this error?
Thanks in advance.
for security reason, WEB-INF folder is not accessible from client side.
put your xml file in other location.
and try again, It will work

can a deployed war/application be edited?

I have an application/war deployed in server. Now at runtime I want to add an xml document to the war/application. can I do that? if yes, what is the path of an war/application for it to be added.
You have to repackage the WAR, redeploy, and bounce the server. It's not that simple.
You can make that data available without the hassle if you put it in a database and have your application access it there.
in the webapps/WEB-INF folder you can find the xml files
It depends on the servlet container/application server.
If you are using Tomcat, wars are getting unpacked to the webapps directory inside the Tomcat directory.
Move webapps/app directory outside the webapps directory, what will cause an undeploy of app
Put your xml file into the app directory
Move app back to webapps what will cause a deploy

Viewing JSPs with Weblogic JSPServlet

We are currently migrating from OC4J to Weblogic. We have an ANT script which builds the EAR file. The ANT also compiles and packs all the .jsp files into a jar. But when I tried to run the application on Weblogic it always returned 404 when trying to access .jsps. So I tried to add a mapping in web.xml for weblogic.servlet.JSPServlet for the URL pattern *.jsp, but I still get 404 when I try to access .jsps.
What could be the problem?
Thanks.
Your EAR file structure needs to be correct.
If you are deplying to WLS, you can deploy either an EAR or WAR seperately, however if you choose EAR file, you must have the the JSP's within the WAR file. You should only need to specify servlet and resource mapping within the web and context xml files.
You must also make sure that you have your .jar files in the library. Otherwise you can run into problems.
Let me know if you need more info.

Categories