BlueJ picture in jar - image

I've just finished a GUI project and I want to figure out how to get an image that I reference into the completed jar file. As of right now I just reference it as:
try {
img = ImageIO.read(new File("<name>.png"));
} catch (IOException e) {
}
in my project.
What do I need to do to get it to show up in my program?

By the time of Jarring, those resources will have become an embedded-resource. That being the case, the resource must be accessed by URL instead of File. See the info page for the tag, for a way to form an URL.
General Tip
Change code of the form
catch (Exception e) {
// ..
To:
catch (Exception e) {
e.printStackTrace(); // very informative!
// ..

Related

Unable to save screenshots in the designated path or attach the screen shot to extentreports in MAC

I have tried many ways to take screenshot on test case failure but nothing works. unable to take a screenshot and attach it to extentreport in MAC os while using selenium.
public void onTestFailure(ITestResult tr)
{
logger=extent.createTest(tr.getName()); // create new entry in the report
logger.log(Status.FAIL,MarkupHelper.createLabel(tr.getName(),ExtentColor.RED)); // send the passed information to the report with GREEN color highlighted
String screenshotPath="./Stest-output/"+tr.getName()+".png";
TakesScreenshot ts = (TakesScreenshot)driver;
File img =ts.getScreenshotAs(OutputType.FILE);
File destination =new File(screenshotPath);
try {
FileUtils.copyFile(img,destination);
logger.addScreenCaptureFromPath(screenshotPath);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(img != null)
{
System.out.println("Screenshot is below:"+tr.getName());
try {
logger.info("Screenshot is below:" + logger.addScreenCaptureFromPath(screenshotPath));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
throws null pointer exception when trying to copy the image from source to destination.
Have all the methods available in stack overflow.
You are unable to attach screenshot into extent report html because you forget to call flush() method that appends the report HTML file with all the tests result/screenshots. There must be at least one ended test for anything to be appended to the report.
Note: If flush() is called before any of the ended tests, no information will be appended to report.
#AfterTest
public void tearDown() {
extent.flush();

PropertiesLoaderUtils.loadAllProperties is not able to load the property file from src/main/resources

I am using PropertiesLoaderUtils.loadAllProperties(abc.properties);
and have placed abc.properties in src/main/resources folder but still it's not able to get this property file.
Code that we tried ::
try {
props = PropertiesLoaderUtils.loadAllProperties("abc.properties");
} catch (IOException e) {
logger.error("Unable to load file", e);
}
Can someone help me out with the possible cause of not picking up abc.properties whereas if I change it to application.properties, its able to load.

JavaFX: Trying to run the command line 'pdflatex myfile.tex'

My question is two parts.
First part:
I am writing a series of latex files, and I would like to compile them.
The command works if I type it manually. so the syntax should be correct. But when I run it from java application, it won't compile.
This code, in Java creates a latex file correctly--as expected.
File latexFile = fileChooser.showSaveDialog(window.stage);
if (latexFile != null) {
try {
writeContentToFile(content, latexFile);
} catch (IOException ex) {
Logger.getLogger(DocumentViewPort.class.getName()).log(Level.SEVERE, null, ex);
}
}
I can compile the generated file in the command line if I type pdflatex and then add the file path and get a PDF file.
but it does not seem to work when doing it from java itself like in here:
try {
Runtime.getRuntime().exec( "pdflatex " + latexFile.getPath());
} catch (IOException ex) {
Logger.getLogger(FileAndContentCreation.class.getName()).log(Level.SEVERE, null, ex);
}
any ideas why?
I tried to read online on many places, I can't find out what part is the problematic one. Any help would be greatly appreciated. Thanks.
Second part
My second part of the question is changing the directory, I am using:
Runtime.getRuntime().exec( "cd " + myNewdirectory.getPath());
But it fails with an error=2
Any ideas how to change the current directory?

BIRT csv emitter and EJB

I want to use csv emitter plugin in a Java EE application. Is it possible? I get the following error:
org.eclipse.birt.report.engine.api.UnsupportedFormatException: The output format csv is not supported.
at org.eclipse.birt.report.engine.api.impl.EngineTask.setupRenderOption(EngineTask.java:2047)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:96)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)
My code:
protected String generateReportFile(IRunAndRenderTask task, IReportRunnable design, IReportEngine engine, String reportType, String reportPrefix, String baseDir) throws BirtReportGenerationFault {
CSVRenderOption csvOptions = new CSVRenderOption();
csvOptions.setOutputFormat(CSVRenderOption.OUTPUT_FORMAT_CSV);
csvOptions.setOutputFileName("C:/birt/logs/csvTestW.csv");
csvOptions.setShowDatatypeInSecondRow(false);
csvOptions.setExportTableByName("data");
csvOptions.setDelimiter("\t");
csvOptions.setReplaceDelimiterInsideTextWith("-");
task.setRenderOption(csvOptions);
task.setEmitterID("org.eclipse.birt.report.engine.emitter.csv");
try {
task.run();// Error here
} catch (EngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
task.close();
return "C:/birt/logs/csvTestW.csv";//fileName;
}
Same code works in a Java SE app.
I had the same problem, but with the pdf format. I solved it by adding org.eclipse.birt.report.engine.emitter.pdf to the plugin Dependencies.
I think the problem here is case of output format passed to in CSVRenderOptions.
instead of using csvOptions.setOutputFormat(CSVRenderOption.OUTPUT_FORMAT_CSV);
try using csvOptions.setOutputFormat("CSV");

JGit - Get all commits (PlotCommitList) that affected a file/path

Hy i am trying to get all the commits that include a specific directory or file of my repository.
I tried the folowing code :
public PlotCommitList getPlotCommits(String path){
System.out.println(path);
PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
PlotWalk revWalk = new PlotWalk(repository);
try {
ObjectId rootId = repository.resolve("HEAD");
if (rootId != null) {
RevCommit root = revWalk.parseCommit(rootId);
revWalk.markStart(root);
revWalk.setTreeFilter(PathFilter.create(path));
plotCommitList.source(revWalk);
plotCommitList.fillTo(Integer.MAX_VALUE);
return plotCommitList;
}
} catch (AmbiguousObjectException ex) {
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
}
return plotCommitList;
}
I don't get just the commits that affected that file. I get some "subLists" of the entire list but not just those commits that affected that file.
Maybe TreeFilter doesn't work how i think? I should use other way to get those commits?
I saw the log command has a path filter but i didn't tried it yet because it returns a RevCommit list and for my PlotCommitList i need a revwalk to use as a source. And also i think i cannot cast RevCommit to PlotCommit.
A guy had the same problem here (1st Answer with fileA and fileB issue) : Link - Click Here
You need to combine the PathFilter with an ANY_DIFF filter:
revWalk.setTreeFilter(
AndTreeFilter.create(PathFilter.create(path), TreeFilter.ANY_DIFF));
With only PathFilter I think what happens is that all commits are selected where the specified tree exists (e.g. all commits starting from the initial commit of that file).
Also see the API docs of setTreeFilter or how the LogCommand does it.

Resources