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

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?

Related

Why is everything inside a BOOT-INF folder and how to get rid of it in case it's breaking my classpath?

I am getting a classic well-known error in my Springboot app when it tries to load a static resource using getResourceAsStream():
java.io.FileNotFoundException: class path resource [blah blah blah] cannot be opened because it does not exist
While doing some basic troubleshooting, I opened the contents of the generated jar file and found that everything in the jar is contained inside a folder named BOOT-INF.
Why is everything inside BOOT-INF?
How do I get rid of this?
UPDATE
Here's the actual relevant part of the code
ClassPathResource cpr = new ClassPathResource(RESOURCE_CLASSPATH_PREFIX + url);
try (InputStream is = cpr.getInputStream()) {
return DigestUtils.sha1Hex(is);
} catch (IOException e) {
throw new RuntimeException(e);
}
Additional Clue
The failing code is inside a ServletFilter. I think this has something to do with class loaders.

Implementing Jump Hosts with SSHJ

Somebody asked for this and there is a pull-request which contains code that somehow was rewritten before it got merged and somebody managed to code a solution based on the pull-request. However, there is no example for the final version in that library.
Therefore, that doesn't really help me with my limited understanding of ssh and all. Basically there are two scenarios I want to solve:
common SSH-session via some jump-hosts:
user1#jump1.com
user2#jump2.com
user3#jump3.com
admin#server.com
ending in an ssh-session where the connecting user is free to work around in that ssh-shell at server.com, i.e. what a normal ssh admin#server.com-command would do in the shell on jump3.com.
like the above but ending in a port forwarding to server.com:80
That is possible with ssh's ProxyCommand, but I want to code this with SSHJ. And that's where I fail to figure out how to do this.
What I have now is
SSHClient hop1 = new SSHClient();
try {
Path knownHosts = rootConfig.getKnownHosts();
if (knownHosts != null) {
hop1.loadKnownHosts(knownHosts.toFile());
} else {
hop1.loadKnownHosts();
}
Path authenticationFile = hop1Config.getAuthenticationFile();
if (authenticationFile != null) {
KeyProvider keyProvider = hop1.loadKeys(authenticationFile.toString(), (String) null);
hop1.authPublickey(hop1Config.getUser(), keyProvider);
} else {
hop1.authPassword(hop1Config.getUser(), hop1Config.getPassword());
}
// I found these methods:
hop1.getConnection();
hop1.getSocket();
// and now what?
} catch (IOException e) {
logger.error("Failed to open ssh-connection to {}", hop1Config, e);
}
I noticed class LocalPortForwarder.DirectTCPIPChannel, but I don't know with what values I should instantiate it or how to use it with the rest afterwards.

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.

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