LWJGL library path for Eclipse

To run an application or unit-test using LWJGL one has to set the java.library.path VM parameter to point to a directory containing the native DLLs.

I have this working fine for my maven build on the command line using a surefire plugin, but it would be nice to get it working within Eclipse. Obviously I can set the VM parameter in the run configuration but it’s painful, especially if I’m writing unit-tests: every test has to have its own run config that I have to set manually.

Done some googling, I can find lots about setting this up for a maven build but not for Eclipse itself. Get the feeling I’m missing some cunning trick - is there some way to set this ‘globally’ for an Eclipse project?

  • stride

I’m not sure if it is that what you ask, but you can set the directory with @BeforeClass (I assumed that you use JUnit for the Tests):


@BeforeClass
public void setLwjglDirectory() {
    System.setProperty("org.lwjgl.librarypath", new File("path/to/natives").getAbsolutePath());
}

Alternatively you could also set the property as the first call in your main method.
Or were you looking for something like this?
I hope that helped :slight_smile:

Would you mind posting your maven config? I am currently bothering with the same thing but I can’t get it to run for some reason :confused:

[quote=""]
That suggestion works nicely, in fact I have a custom JUnit test-runner that creates a LWJGL display so there is an active OpenGL context for the tests to use.

One slight change is that you have to set a string parameter as the property:


		System.setProperty( "org.lwjgl.librarypath", new File( "target/natives" ).getAbsolutePath() );

i.e. the absolute path at the end.

Sorry hadn’t noticed this reply, here’s an extract from the POM:


	<properties>
		<lwjgl.version>2.9.0</lwjgl.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			
			<plugin>
				<groupId>com.googlecode.mavennatives</groupId>
				<artifactId>maven-nativedependencies-plugin</artifactId>
				<version>0.0.7</version>
				<executions>
					<execution>
						<id>unpacknatives</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>copy</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<forkMode>once</forkMode>
					<argLine>-Dorg.lwjgl.librarypath=target/natives</argLine>
				</configuration>
			</plugin>
		</plugins>
	</build>

Hope this helps.

  • stride

Oh… you’re right, I overlooked that! Thanks :wink:
Fixed it :slight_smile: