Serve Modules without publishing not working in Helios - java

I have recently moved a webapp I have been developing to a new machine running 64bit Eclipse Helios (Service Release 2) and I am using Maven plugin M2Eclipse.
I have deployed on a local tomcat install through Eclipse and everything is ok (more or less), but I want to select the option "Serve Modules without publishing", but when I select this option I get errors:
log4j:ERROR Could not read configuration file from URL [file:/C:/butterfly/svn/trunk/micro/src/main/webapp/WEB-INF/classes/log4j.properties].
java.io.FileNotFoundException: C:\butterfly\svn\trunk\micro\src\main\webapp\WEB-INF\classes\log4j.properties (The system cannot find the file specified)
The log4j.properties file is not there, as in my source directories in lives in src/main/resources - at build it then gets copied over to target/WEB-INF/classes/..
Eclipse seems to be mixing the expected target directory with the src directory so not finding it.
Im not sure if this is happening for just the properties file or if the same problem will occur looking for all built resources.
I have seen these issues:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=318449
http://www.eclipse.org/forums/index.php?t=msg&goto=661045&S=25bafd85b11e042c169ecf1752bfa479
but they seem to be slightly different or already fixed (My Helios is a new download from last weekend)
Anyone experience this or know how to resolve?

From here: "The Serve modules without publishing option does what it says. Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader". I would expect eclipse to emulate serving every class / resource file (including log4j.properties) from WEB-INF/classes after you build the project. As a workaround, what about creating a "classes" folder inside WebContent, copy log4j.properties file here and see if the classloader gets happy?

Related

Rest service in Java runs from Tomcat server but not inside Eclipse

I am unable to find another article that solves my problem but am happy to hear about one if you know the answer.
I have a RESTful service built in Java with Eclipse. It uses Spring and all of its bells and whistles.
After much work with configuration files, I am able to build the service into a war file, deploy it to my Tomcat webapps folder, and run it from standalone Tomcat. However, it still throws several errors on start when I try to start it from a service defined within Eclipse. The errors are the same errors that I was seeing before I got the config files correct for standalone Tomcat. The errors are about the inability to create the required beans because of references to properties that can't be found.
How did I get it running in Tomcat? I added a couple of .properties files to define properties needed by the beans that get launched at startup and then added a 'set CLASSPATH=...' line to the setenv.bat file in the Tomcat bin folder. This new line adds the properties files into the CLASSPATH. That seems to have fixed everything from standalone Tomcat.
So, my question is, "How do I make these same changes inside my Eclipse server?" I have added the properties folder with the property files under the config folder in Eclipse, just like it is in my native Tomcat folders, but I do not know how to modify the CLASSPATH string to specifically point to my .properties files (as I have done in the setenv.bat file for standalone Tomcat).
I think I understand the problem, but have no idea about the solution.
Thanks for listening.
Dave
Eclipse does not use any *.sh/*.bat files to startup Tomcat. In order to modify the way the server is started you have to open the configuration UI of the server by double-clicking on the server in the Servers view.
From there you will be able to modify the classpath of the system classloader through "Open launch configuration".
Another important setting is "Server path" which tells Eclipse, the value of $CATALINA_BASE. You can modify it only after removing all modules and cleaning the server. It is useful to set it to an easily accessible directory: this way you can verify directly that Eclipse didn't mess up your application deployment (sometimes it "forgets" to copy some libraries).
The "Configuration path" setting tells Eclipse where to find the files (but not subdirectories) that will be copied into $CATALINA_BASE/conf.
Remark: if your application requires you to add libraries to the top classloader, there is probably a problem in your project. The "missing" libraries should be added to WEB-INF/lib of your application instead: look into the "Deployment assembly" of your Eclipse project configuration.

(Tomcat 7) Deployed jar not finding files

I deployed a war file onto a Tomcat 7 instance running on a remote Linux machine and I'm getting FileNotFoundExceptions.
One of the referenced jars in the project, which contains code that I did not write, uses several files (which I have included, but it is not finding). These files are located in the classes folder. It appears the classpath I have set for the project is being ignored by this jar. These files that it uses, e.g. .properties files are external to the jar.
Here is an example of how it is invoking the files:
FileOutputStream fos = new FileOutputStream("Key.ser");
I was getting these errors when developing the source project in Eclipse. I was able to configure the project to tell it where to find these files via Run Configurations -> Arguments -> Other but the exported .war file appears to not have this bundled with it, only the source project has it. Now I'm seeing them again when trying to deploy the application to Tomcat on another server via war file.
How do I configure the deployed jar file in the deployed Tomcat 7 webapp to find these files that the jar uses? I am loathe to change the code since I did not write it so am really hoping to avoid this.
I am able to get this to work on a local Tomcat 7 running on Windows instance integrated with Eclipse as explained earlier so I'm wondering if maybe this can be duplicated?
You will not be able to find the file by simply referencing the file name using FileOutputStream. You are correct to place the file in the 'WEB-INF/classes' directory, which will allow it to be located on the classpath.
To load the file, you need to load it as a classpath resource using something similar to this:
String classpathLocation = ""Key.ser"";
URL classpathResource = Thread.currentThread().getContextClassLoader().getResource(classpathLocation);
// Or if you want it as an inputstream:
InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(classpathLocation);

Java Web Project not building correctly

I've got a Java Web Project which I'm deploying to a Tomcat embedded in Eclipse's Servers Plugin, alas, when I navigate to the location of that webapp after publishing/starting the server, the .class files are all missing. I can navigate as far as ProjectName\WEB-INF\classes\path\to\packages\ -> All packages are empty.
Any Idea how to solve this problem?
Edit
Build Automatically is checked and it compiles just fine for another web project I've just included, just not for the one specified
Edit 2
Reinstalled Eclipse (because why not) - nothing's changed, works for Project #2, doesn't work for Project #1. Not even the path to the packages is existant now. The content of the src folder (that's supposed to be moved to WEB-INF/classes) isn't there at all - but the resources (I've got a resources folder with the same deployment assembly command) are.
A few steps to perform to restore sanity...
Refresh your project. It is possible that something was modified on the file system external to Eclipse.
Kick of Project -> Clean.
Now look at your project (not the deployed location) on the file system. Do you see the expected files in the /bin directory (or whatever you may have changed class output directory to)?
Let's now try exporting a war using the wizard. File -> Export -> Web -> WAR or something like that. Check the WAR contents. Are you .class files there?
If everything is good so far, there is nothing wrong with your project. The Tomcat server adapter just got confused.
In the Servers view... Make sure Tomcat is running. Next right click on Tomcat and select add/remove projects. Remove your project. Confirm that your web app is no longer accessible.
Now re-add your project via add/remove projects or invoke one of the run as actions.
The above should reset Tomcat server adapter and hopefully things should work as expected.
Check if you had deleted or moved your external JARs associated with the project on your IDE. I had moved it and ran into the same issue.

Setting the working directory for an eclipse plug-in

In the Eclipse plugin I am developing, I am querying some Prolog files that are in my development directory. In addition, an initialization file located at the root of my working directory is automatically loaded by the Prolog engine I am using. All these files are resources of my plugin.
When executing my application as a java standalone the only thing I need to do is to set, in the Eclipse Run Configurations dialog, the working directory to my default output directory. Then when executing my application the Prolog engine starts at the directory where the initialization file is located, and it is able to locate and load the prolog files of the application when needed. This Prolog engine is started from Java using the JPL library.
My problem started when I wanted to build an Eclipse plug-in of my application. Apparently the default working directory for plugins cannot be changed in the Run Configurations dialog (at least that is the case in my Mac setting), otherwise an infinite list of exceptions appear when the plug-in is executed.
So what I would like to know is if there is another way to setup the working directory for a plugin, both during the development lifecycle (i.e., when I launch my plugin as an Eclipse Application) and in production (i.e., when the plugin is in the plugin directory).
Thanks !!
Working directory is set for the application not a plugin. I can imagine the mess if all plugins would try to set the working directory to their liking...
Files in a plugin can be found using the Bundle class which can be accessed using plugin activator. This will give you a URL that most likely points to a JAR entry. FileLocator class can be used to "convert" that URL to a file URL (file will be extracted from JAR).
URL url = Activator.getDefault().getBundle().getEntry("file path in JAR");
URL fileUrl = FileLocator.toFileURL(url);
File file = new File(url.getPath());
If the file MUST be in the working directory then you can copy it there.

Blackberry runtime error: FRIDG: could not find img/logo.png

I recently had to prepare a BB app for submission to the BB app world, but I have an issue when running the app. Basically, I've created a new Blackberry project, using the "use existing source" option to point to the sources I've got from the developer that actually developed this app. Building the application just works, but when I want to start the app it immediately quits with a NullPointerException.
When debugging the application, the debugger halts at the following line:
Bitmap bitmaplogo = EncodedImage.getEncodedImageResource("img/logo.png").getBitmap();
With the following error:
[0.0] FRIDG: could not find img/logo.png
I do have an img/logo.png, which is located in /res/img/logo.png. Attempts of specifying the path as "res/img/logo.png", "/res/img/logo.png", "logo.png" have not worked. I personally don't think that's the issue here, this exact code base works perfectly for another developer. I'm more inclined to start looking into tooling, JDK/JRE versions, project settings. Maybe resource files should be explicitly included in the build?
Some other information:
My Blackberry project uses Blackberry JRE 5.0.0 as the JRE system library
I have Oracle Java SDK 6 Update 26 installed
Using Blackberry Java Plugin for Eclipse 1.3.0
On Windows XP SP2
Has anyone encountered the same issue before?
Filenames and extensions are case sensitive. logo.png and logo.PNG are different files from application's point of view. So, be careful with naming files and folders.
The root folder for images you get in your application is the root folder of your source files package.
For instance, if you have the following folder structure:
YourProject
src\
com\
company\
etc\
img\
Then the root folder for your images will be: YourProject\src
Image files located in YourProject\img folder are invisible for your application code, unless img folder is located in YourProject\src and the full path is:
YourProject\src\img
and your image file has the full path like that:
YourProject\src\img\logo.png
In this case you can load the image via specifying it's path: img\logo.png
and without it, just via specifying: logo.png
Specifying the full path is recommended if you have several images with similar filenames.
If you have several files logo.png in your project, and you load it via specifying only file name "logo.png" then the first found image from your project will be loaded.
Resume: transfer your img folder into the src folder.
Not sure if this is the same as your problem, but when I get those types of errors, it usually means that I need to force the project in Eclipse to refresh (right-click on project and choose Refresh) and then rebuild.

Categories

Resources