Comments (3)
Hi @smiklosovic
Unfortunately, there is no easy way to do this. I can suggest only this solution:
public class ClassPathTest {
@Test
void shouldAddCustomLibraries() {
EmbeddedCassandraFactory cassandraFactory = new EmbeddedCassandraFactory();
cassandraFactory.setArtifact(new CustomArtifact(Version.of("3.11.6")));
Cassandra cassandra = cassandraFactory.create();
try {
cassandra.start();
}
finally {
cassandra.stop();
}
}
private static final class CustomArtifact implements Artifact {
private final Artifact delegate;
private CustomArtifact(Version version) {
this.delegate = Artifact.ofVersion(version);
}
@Override
public Distribution getDistribution() throws IOException {
Distribution distribution = this.delegate.getDistribution();
Path destination = Files.createTempDirectory("apache-cassandra-" + distribution.getVersion());
//clean up this directory on jvm exit
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
FileUtils.delete(destination);
}
catch (IOException ex) {
//ignore;
}
}));
//copy everything from an original directory except javadoc, doc..
FileUtils.copy(distribution.getDirectory(), destination, (path, attributes) -> {
if (attributes.isDirectory()) {
String name = path.getFileName().toString().toLowerCase(Locale.ENGLISH);
return !name.equals("javadoc") && !name.equals("doc");
}
return true;
});
addLibraries(destination);
return new DefaultDistribution(distribution.getVersion(), destination);
}
private void addLibraries(Path destination) throws IOException {
Path libDir = destination.resolve("lib");
//copy libraries...
try (InputStream resourceAsStream = CustomArtifact.class.getResourceAsStream("/mylib.jar")) {
Files.copy(resourceAsStream, libDir.resolve("mylib.jar"));
}
}
}
}
from embedded-cassandra.
According to cassndra.in.sh
it is possible to extend classpath via EXTRA_CLASSPATH
environment variable, so in your case, you can do something like this:
EmbeddedCassandraFactory cassandraFactory = new EmbeddedCassandraFactory();
cassandraFactory.getEnvironmentVariables().put("EXTRA_CLASSPATH", "path to your libraries")
from embedded-cassandra.
@nosan nice one, I invented my own solution, similar to yours, I am just adding that JAR directly into distribution dir so it starts with that automatically, however your original solution is cleaner. The second way to do it is the best and the simplest one.
from embedded-cassandra.
Related Issues (20)
- OpenJdk not Supported under Windows (embedded-cassandra-junit5-test:3.0.3) HOT 1
- Java 11 support HOT 5
- Check that if Embedded Cassandra is already running that don't start a new instance HOT 1
- Cassandra 4.x doesn't work on Windows HOT 2
- Multiple test case run throwing error HOT 1
- fallback to cassandra.bat wont work HOT 12
- Configuration file is not generated properly on windows HOT 3
- some issues with stopping HOT 2
- Apple Silicon m1 support HOT 2
- Java 16 support. HOT 7
- Loading Schemas using forEachStatement takes a long time HOT 1
- Does not working on Windows 10 HOT 2
- How do I set up authentication? HOT 1
- Error during Cassandra start with openjdk-11 HOT 7
- Unable to start embedded cassandra using JDK11 HOT 2
- Embedded Cassandra 3.1.0 would not start with JDK 11 HOT 3
- Unable to start Embedded Cassandra HOT 1
- Keyspace problem HOT 3
- Allow to configure if working directory should be deleted on exit HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from embedded-cassandra.