Categories
Development Java

class Foo is public, should be declared in a file named Foo.java

When working with Java you might encounter this error. The reason for this is that you have tried to declare a public class in a file with a different name. Each java file can only contain one public java class, which is named the same as the java file itself. If you need another class inside your other class you should looking into private inner classes.

Categories
Development Java Linux Red Hat Software

jpackages error: Missing Dependency: /usr/bin/rebuild-security-providers

Jpackages on Red Hat has a nifty bug that causes dependency errors.

Luckily, somebody has created a fix as a rpm package 🙂

wget http://plone.lucidsolutions.co.nz/linux/centos/images/jpackage-utils-compat-el5-0.0.1-1.noarch.rpm
rpm -ivh jpackage-utils-compat-el5-0.0.1-1.noarch.rpm

And then jpackages works.

Categories
Java

Tips for implementing a custom JAAS login module for Jetty

1) jetty-web.xml

You can gather all specific settings for Jetty in the file WEB-INF/jetty-web.xml, remember to also specify paths for the role principals if you use your own classes for that.

Example jetty-web.xml file:

<!-- Jetty specific config file -->
<Configure>

<!-- Tell jetty where to find login config -->
<Call name="setProperty">
	<Arg>java.security.auth.login.config</Arg>
	<Arg>WEB-INF/login.config</Arg>
</Call>

<!-- Bug fix for Jetty to properly handle login config in a per-project setup -->
<Set name="serverClasses">
	<Array type="java.lang.String">
		<Item>-org.mortbay.jetty.plus.jaas.</Item>
		<Item>org.mortbay.jetty</Item>
		<Item>org.slf4j.</Item>
	</Array>
</Set>

<!-- Create login realm -->
<Get name="securityHandler">
	<Set name="userRealm">
		<New>
			<Set name="name">*NAME OF YOUR REALM*</Set>
			<Set name="LoginModuleName">*NAME OF YOUR LOGIN CLASS*</Set>
			<Set name="roleClassNames">
				<Array type="java.lang.String">
					<Item>*PATH TO YOUR ROLE PRINCIPAL CLASS*</Item>
				</Array>
			</Set>
		</New>
	</Set>
</Get>
</Configure>

2) Adding roles to a user in commit

When you want to give a user roles(like admin, moderator etc), you can add those to the user when he or she is authenticated and commit is called upon:

	public boolean commit() throws LoginException {
		MyUserPrincipal user = new MyUserPrincipal("username");

		//Add logged in user as first principal
		subject.getPrincipals().add(user);

		//Add roles for the logged in user
		subject.getPrincipals().add( new MyGroupPrincipal("admin") );
		subject.getPrincipals().add( new MyGroupPrincipal("moderator") );
	}
Categories
Java

Debugging GWT: Did you forget to inherit a required module?

You will receive this error if you are using classes in your GWT project that GWT does not have access to. Make sure that you have added something like this in your gwt.xml file, within your module element:

    <source path="path.to.classes" />
Categories
Java

Eclipse Workspace In Use Or Cannot Be Created

You may recieve the error message “Eclipse Workspace In Use Or Cannot Be Created” From Eclipse when trying to start up Eclipse, this typically means that Eclipse is already running.  If you have not started Eclipse, try to locate Eclipse in your operating systems task manager and kill it. You can also consider killing any java processes running if you cant find any Eclipse processes.

Categories
Development Linux

SVN gives “attempt to write a readonly database” error

You can get a meeting with this error message when trying to commit something to a SVN repo, this is caused by wrong permissions on a file on the SVN server. The file “rep-cache.db” will most likely have wrong permissions like the group not having write access to the file. A simple chmod g+w on the file will be enough for the error message not appearing again.

Categories
Java

HttpClient: Target host must not be null, or set in parameters

If you have the following code failing:

HttpGet httpget = new HttpGet(“www.host.com”);

Then the error is pretty easy to solve:
The problem is that you have not added a protocol to the URL, so change it to:

HttpGet httpget = new HttpGet(“http://www.host.com”);

And then it will work as wanted.

Categories
Java

java.util.concurrent.CopyOnWriteArrayList not found in java.net.URLClassLoader

Simply said: You are most likely trying to run a java app on a too old version of Java, try upgrading to java 1.6 and see if that helps.

Categories
PHP

PHP GeoIP: Required database not available at /usr/share/GeoIP/GeoIP.dat

This error is most likely caused by you missing the GeoIP.dat file. Simply download it from Maxmind.com and place it in /usr/share/GeoIP/ (or another path if that is the case)

cd /usr/share/GeoIP/
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip  GeoIP.dat.gz

And that should be enough, no restart of any service is needed 🙂

Categories
Java

java.io.FileNotFoundException: no segments* file found (Solr)

You will receive that error from Solr when you (for example) have removed the index data, but not the index folder itself. Simply remote the folder that are supposed to contain the index data, and Solr will then recreate the folder, and the data when you start a indexing job. 🙂

Categories
Development Java

The hierarchy of the type Foo is inconsistent

You can get the error:

The hierarchy of the type *classname* is inconsistent

If you are trying to compile a class that requires another class not available. Normally due to compilation errors in the dependent classes. So fix the classes needed by the main class and try again.

Categories
PHP Ubuntu

sh: phpize: not found

When using pecl, or something else that require phpize, you may get a warning saying that phpize is not found, even when you have PHP installed on your server.  In order to use phpize you need to install the PHP development packages, normally named php-devel.

For Debian/Ubuntu, you can fix this by running:

sudo apt-get install php5-dev