Archive for the ‘Coding’ Category

Maven Problem (Id can not be null)

Tuesday, July 13th, 2010

Working with Maven I came across a very weird issue. I attempted to build a new project, and received a Fatal Error: ID Can Not Be Null. Basically a Java.Lang.NullPointerException. I work in a corporate environment so I had an idea of which parent POM was having issues, but it didn’t quite click in my mind until about 5 minutes ago. After researching the net for the past few hours, I finally had my AHA! moment and decided to try it out. The solution to this problem is as follows:

Inside the POM.XML file for the project you are currently working with, you should have something like the following:

<parent>
<groupId>com.mycompany.or.something</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<relativePath>../../parent/</relativePath>
</parent>
The groupId tag is very important, as in my case this is where the problem existed. I navigated to the local maven repo (~.m2/repositories) and through the directories til I came to the following dir:
~m2/repositories/com/mycompany/or/something/parent/1.0/
Inside this directory was a parent pom file. I opened it up in Notepad++ and looked through the tags. Sure enough, the repositories tag did not contain an ID element. I simply added one in ( <id /> ) and voila, problem solved.
Hope this helps someone in the future, because it had me banging my head against everything I could possibly find – from walls to staplers to windows (oh my!)

Unix Lucas Fork Program

Saturday, April 5th, 2008

I wrote this program for a class a few semesters ago. It is a Lucas Number calculator that uses forks/pipes (a requirement of the project). Works great, hopefully it will help someone out there! It is also available for download below.


/* Lucas Fork & Pipe*/
#include <stdio.h>
#include <time.h> // to print the time

float fib(int); // fibonacci function, recursive
int fork(void);
void sleep(unsigned);

int main(void)
{
int n; // input variable
int i; // for the loop
int start = time(NULL); // get the time the process started
char buf[100]; /* store the characters read */

// pipe needs an integer array of size 2
int fd[2];
printf("Create the pipe\n\n");
pipe(fd); /* fd[0] read; fd[1] write */

printf("Enter a number: ");
if (scanf("%d", &n) != 1) { // check to make sure there is input
printf("Input error.\n");
return 1;
}
printf("Create the child process using fork\n");
if (fork() == 0) { // child process
close(fd[1]); /* close write end */
printf("child is running...\n");
printf("about to read from the pipe\n");
n = read( fd[0], buf, 100); /* child reads from pipe */
printf("after reading from the pipe\n");
printf("the value of n is: %d\n",n);
printf("the value in the buffer is: %s\n\n", buf);
for (i = 0; i <= n; ++i) {
printf("fib(%2d) = %d\n", i, fib(i));
sleep(1);
}
}
else { // parent process
close(fd[0]); /* close read end - not needed for this example */
printf("parent is running...\n");
printf("about to write to the pipe\n");
write( fd[1], "Writing to pipe\n", n); /* parent writes to pipe */
printf("after writing to the pipe\n\n");
for (i = 0; i < n; ++i) {
sleep(1);
printf("Calculating...elapsed time = %d\n", time(NULL) - start);
}
}
return 0; // exits program
}

float fib(int n) // fibonacci function, recursive
{
if (n <= 1)
return n;
else
return (fib(n - 1) + fib(n - 2));
}

Lucas Fork Source File (zipped)