Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Wednesday, September 21, 2016

Eclipse Tip: Using an Built-In Variable to Customize a Linked File Location in the Build Path

Today, we came across this issue and I thought I would share this information since we couldn’t find much out on the net about this subject. Warning: This is a very narrow use case.

Author Note: This post is my first java-centric blog since I have moved on from my Domino/XPages role. I hope to blog more about java related topics in the coming months, thanks to those who encouraged me to continue blogging. I have several ideas in the pipeline.

Background:  My Tech Lead and I are creating three java web services.  We often pair program but also want to be able to work alone. We use Rational Application Developer, which is a flavor of the Eclipse IDE. To manage our code, we use SVN for source control, and I making the assumption that everyone knows the basics of how that works. We are both currently working local, and the code is not on a shared server yet.

As part of our project, there are some file resources in which we need to read. These resources are in a folder that we need to add to our build path and to do so we use a linked source folder.  Also worth noting, we are not allowed to use Maven in our environment.

The Problem:  When each of us, link to the source folder on our hard drive it is stored with an absolute path. When we commit this to our shared repository and then Update to Head, we get the other person’s absolute path.  Each of our user folders is based on our five digit ID so the path is always different.  We needed a way to avoid absolute paths when we link source.

The solution: We used a variable to specify the Linked File Location which translates to our individual paths. This works well, but it is quite confusing initially, until you understand how it works.

How to Implement Solution:

Follow these five steps to use a variable for the Linked File Location:

 1) Configure the Build Path of the project and click on the ‘Source’ tab as show here.  



2a)  
If creating a new location, click on ‘Link Source


2b) Alternatively if you already have a link source then select it, and press edit to see this similar window


3) From either window above, select the ‘Variables’ button and you will see a window like this. These four variables/constants are created by default. You could also add your own here if you have a need to do so.  Make a note of the variable name or write it down because you cannot copy the name to the clipboard.


4) In the linked file location add the variable “WORKSPACE_LOC” instead of the concrete path. Hit 'Finish' to save.


The variable will show in the Build Properties now prior to hitting OK to save. However once it is saved, it will show the complete path without the variable you entered.  This is very confusing.


5) Despite the confusion, if you followed the steps right, the variable is saved. I would recommend verifying that the variable change took by opening the .project XML file and checking to see if the variable is in the path.  You need to use the Navigator window to find the .project file.  If the change took, it will look like below.

Monday, December 29, 2014

Using Domino Designer's 'Sign Design' to solve strange Java exceptions

Today, I reached out to another XPages developer who works on the same project in order to help me get past a strange error I was getting. The issue was that Java code within an XPages application that previously worked fine started failing, even though it had not been altered. He had experienced this issue before and knew what to do to fix it. The fix I am about to describe was new to me, so I felt it was worth sharing here.

The exception I was getting was this:
javax.servlet.ServletException: java.lang.Error: Unresolved compilation problem:  

When I first got the error, I naturally thought that it was something that I had changed. I didn't know what to make of an unresolved compilation problem, it seemed a bit generic, like the check engine light on your car. Even after I was able to isolate the line causing the problem, it made no sense because it was run of the mill Java code, the kind of snippet you use and reuse. In this case, it was a variable resolver that gets a handle to the current session.  

My coworker suggested performing a "Sign Design" on the whole application. To do this, right click on the application name, then click "Application", and then "Sign Design". Sure enough, this fixed the issue, no more Java exceptions. This is one of those fixes that is worth trying when nothing else is making sense. Of course this issue is most likely to happen for applications where work is shared by a team of developers, as is the case here. The downside of this fix of course, is that you lose some of the history, and it looks like you touched every design element.
The way to find the option to Sign Design is to right-click on the application title, and choose Application, and then choose Sign Design.

PS:  I want to wish Best Wishes for 2015 to all who stumble across my ramblings.

Wednesday, August 20, 2014

Trouble Using the Jar Design Element in XPages

It has been a while since posting, I have not forgot about blogging, but really have not done anything blog worthy.  In one of my projects, we have to talk to a mainframe application (not the tables) and perform various tasks.  The mainframe connection is made through Hostbridge technology, and packaged for me by our java developer in a jar that I can interact with using the java beans I use for business logic in my application.

As we are in proof of concept mode, the java developer sends me the jar every time he makes a change and I place it in my NSF using the new Jar design element. Unfortunately, so far it hasn't been as easy doing this as I expected.  I dropped the jar file in, and then was able to write code to call the public methods using the java bean.  So far so good, after adding the proper imports the code compiled fine.

At runtime, it would choke and give me a NoClassDefFoundError exception. This of course is really confusing because to me, the time to decide that you can't find the class should be compile time. I tried several times cleaning and rebuilding the application before turning to Stack Overflow with this question: http://stackoverflow.com/questions/25371817/the-contents-of-jar-file-not-found-using-jar-design-element-of-designer-9

I recieved two helpful answers from Stephan Wissell and Frantisek Kossuth.  The first thing I tried was removing the application, re-adding and verifying the build path which Stephan suggested.  This worked, and I was able to continue on without getting the same exception.

The next day it was necessary to change the package name we were using inside the jar.  I was able to fix my own java code by correcting the import and again it compiled fine.  Unfortuately at runtime,  I started getting the same NoClassDefFoundError exception again.  This time nothing I tried worked.  I spent a long time checking build paths, and trying to use the WebContent/WEB-INF/lib instead of the jar element.  I did discover along the way that the jar element actually places the file in the the lib folder on its own.  I also discovered that the Package Explorer makes it appear that the file is not there, but if you use the Navigator instead you can see that the jar file is present in that folder.

Franitisek in his answer, linked to another Stack Overflow question, one that I discovered before I asked my question.  In that question, the person who answered Panu Haaramo made a comment on his answer directing the OP to this blog post: http://lotusandjava.blogspot.com/2012/10/xpage-javalangnoclassdeffounderror.html

In this post, the author remarked that the only thing that worked was renaming the class.  So instead of renaming any classes, I decided to rename the jar file using the right-click menu option rename.  I did not rename using the O/S or have the java developer send me a new jar.  To my amazement, this worked, and the exception went away and I am now back in business.  I probably spent at least 4 hours at work today struggling with this issue, so I am hoping this post will save someone that trouble.

The bottom line

If you are getting a NoClassDefFoundError exception and using jars, try renaming the jars using the right click menu. It is easy, and it just might work. (You can always rename them back later, although I haven't actually tried that yet)

If someone at IBM sees this post, this might be something to look into fixing in the next release. :)


PS.  I am looking forward to attending MWLUG next week, hope to see some of you there.

Friday, June 21, 2013

Simple Fix in Eclipse for when your Managed Bean Cannot Be Instantiated

Today, I added a second managed bean to my application.   I wrote the Java code and added the bean name, class, and persistence to my faces-config.xml file.

No matter what I did, as soon as tried to reference the bean, I would get an ClassNotFoundException.   Basically the application was not seeing the reference in the faces-config file.   I spent most of my energy thinking I somehow had improper syntax in the file.

A quick search found this Stack Overflow, and the comment by Mark Leusink did the trick.   I did a Project  | Clean in Eclipse, and the managed bean worked as expected.   The Project | Clean will launch a window where you can choose any or all of the projects in your 'Application' window.

Hopefully this will be helpful to someone.  I know I am going to try it whenever strange things are happening in my xpages projects.  BTW:  I am using Notes 9.

Thursday, May 9, 2013

Compare with Local History in Eclipse

This post is dedicated to something I wished I learn a bit earlier in my xpages development.   There is a built-in feature of Eclipse called Compare With > Local History.   I have never even knew about this feature until I was researching the issue in the last post where I couldn't open any xpages.  Someone suggested that you use this feature to fix that problem.  While it didn't help me with that issue, I was glad that it was now on my radar.  Today, I need it since I messed up the control I was working on.


To use this, simply right click and choose Compare With, then choose Local History.  Eclipse will open the Local History window, and you can choose the version to compare by revision time.   There is also an option to Replace With > Local History.


The Text Compare window shows the two versions side by side and points out the differences.   It is really cool how Eclipse visually compares them for you.  Also notice, on the right, you can see the Local History window.  If the history I picked doesn't help I can choose another time until I find the right one.

BTW:  I am going on vacation tomorrow, so I won't be posting again for a while!