I create project in Intellij Idea, add tess4j 2.0 from maven, write test application. When I start debug all works fine. When I click "build artifacts" and launch jar file I haven't any result, no errors, nothing.
public class MainApp {
static String fileName = "C:\\Users\\Alex\\Google Drive\\TW\\LIB\\Tess4J\\eurotext.png";
public static void main(String[] args) {
try {
System.setOut(new PrintStream(new File("output-file.txt")));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Start");
ITesseract instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(new File(fileName));
System.out.println(result);
} catch (TesseractException e) {
System.out.println("Error");
System.out.println(e.getMessage());
e.printStackTrace();
}
System.out.println("End");
}
}
Output when debug
Start
The (quick) [brown] {fox} jumps!
Over the $43,456.78 #90 dog
& duck/goose, as 12.5% of E-mail.........
End
Output when launch jar
Start
No "Error", no "End". How it's possible?
I had the same issue. Sometimes it doesn't load classes correctly for some reason. here's how i was able to get it fixed for some far.
Build your artifact and then Remote debug your jar with intellij.
Find out in which line your application breaks.
Then wrap it with try{... line where application breaks..} catch(Error e){e.getMessage(); }
You can see the error message in variable "e" in debug output. So you can determine the issue.
May be this is not an appropriate way to do it. But this is how i was able to track down the errors in my jar file.
How ever it is best to use this as a temporary way to track the errors in your jar and to find out why it breaks and then find out correct way (Which is i'm not currently aware about.. but however got to heard about some library called One-Jar) to build jar without getting any errors on deployment.
Related
I downloaded and installed the free Spire.Doc.jar file to work with .docx files. When I run it within Netbeans the functionality works fine however when I attempt to build the program I am getting the following error:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.8'
Note: Creating static metadata factory ...
error: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1
not found
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1 not found
I have added the .jar file to my class path however there appears to be a class file missing from the com.spire.packages location.
Does anyone know if this is a Netbeans issue or does it look like there is an issue with the .jar file? I find it strange that it works when I run it within Netbeans but the above error occurs when I attempt to build the project.
I managed to get my application to build. What I had to do was remove the following code from my class and then it worked:
document.getMailMerge().MergeImageField = new MergeImageFieldEventHandler()
{
#Override
public void invoke(Object sender, MergeImageFieldEventArgs args)
{
mailMerge_MergeImageField(sender, args);
}
};
private static void mailMerge_MergeImageField(Object sender, MergeImageFieldEventArgs field)
{
String filePath = field.getImageFileName();
if (filePath != null && !"".equals(filePath))
{
try
{
field.setImage(filePath);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm not sure why it didn't work with this included however I got this code from the following website:
https://www.c-sharpcorner.com/article/how-to-perform-mail-merge-in-word-document-in-java/
therefore I will inform them in case this happens to someone else in the future.
I'm wanting to launch the program from a Java application, with some luck. Most programs are started without problems, but some seem to not execute properly(?).
The code I'm using is very simple:
private static void exec() {
ProcessBuilder builder = new ProcessBuilder("C:\\Users\\Fillipuster\\AppData\\Local\\Discord\\Update.exe");
try {
builder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
...and works for almost all executables (*.exe). Discord is purposefully placed in the example, as it is one of the programs that cause this problem. (along with Messenger For Windows and GOG Galaxy).
The behavior is simple, and the same for all executable that causes this; a command prompt quickly pops into existence and then promptly disappears (pun intended) - resulting in the application not being launched.
Sifting through Google and Stack Overflow proved a futile effort, and at this point, I'm at a complete loss.
Any help/input is much appreciated.
Thanks to John, who pointed out that even launching the the Update.exe file "manually" results in the same behavior, I've found the problem.
It seems that when launching Discord successfully, one is actually launching a shortcut that gives a parameter to the executable. In this case:
--processStart Discord.exe
This means that the following code will in fact start Discord:
private static void exec() {
ProcessBuilder builder = new ProcessBuilder("C:\\Users\\Fillipuster\\AppData\\Local\\Discord\\Update.exe", "--processStart", "Discord.exe");
try {
builder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
Thanks to John and all the other commenters.
No TerminalFacade for lanterna - Java
Eclipse gets me this error
TerminalFacade cannot be resolved
For this code
Terminal terminal = TerminalFacade.createTerminal(System.in, System.out, Charset.forName("UTF8"));
I have looked in the source files and cannot find that class anywhere, I have imported it with jar, and direct source, but neither worked. Not sure why this class doesnt exist.
Nm they replaced it
If you look in the source src they use this now
try {
Terminal terminal = new DefaultTerminalFactory().createTerminal();
} catch (IOException e) {
e.printStackTrace();
}
I am trying to develop a module that can update my running Java Desktop App.
The problem is that I have to replace the actual running jar with another jar, all the while displaying an image and a progress bar with the remaining time of the update process.
One solution I thought about is that I can put a jar in my main jar, and when launching the update process, to extract that second jar which will display the image and the progess bar, and also which will replace the old main jar with a new main jar.
My question is if this is possible and how can I do it.
I do not have a lot of experience with java and java packaging so if you have any examples or links, it would be of great help for me.
Thank you very much.
R.
Run this code when press UPDATE button ..
if(Desktop.isDesktopSupported()){
try {
Desktop.getDesktop().open(new File("update.jar"));
System.exit(0);
} catch (IOException ex) {
}
}
This will open update.jar and close main.jar. Now run this code from main class of update.jar
//wait sometime for terminate main.jar
try{
Thread.sleep(5000);
} catch(Exception e){
e.printStackTrace();
}
if(isUpdateVersionAvailable()) { //first check update from database
if(copyMainJarFileFromServer()){ //copy newMain.jar from server and paste
new File("main.jar").delete(); //delete main.jar
rename(new File("newMain.jar")); //rename newMain.jar to main.jar
}
}
boolean isUpdateVersionAvailable() {
//todo
}
boolean copyMainJarFileFromServer() {
//todo
}
void rename(File file){
file.renameTo(new File("main.jar"));
}
You can have a starter jar that checks for updates and launches the app from the main jar.
It will show start logo, an image, that standard java can display at start-up.
The start0er could also be used to restart the app in another interface language.
package starter;
...
public class StarterApp {
public static void main(String[] args) {
String workDir = System.getProperty("user.dir");
Path mainJar = Paths.get(workDir + "...");
Path nextMainJar = Paths.get(workDir + "...");
if (Files.exists(nextMainJar)) {
Files.copy(nextMainJar, mainJar, StandardCopyAction.REPLACE_EXISTING);
}
URLClassLoader classLoader = new URLClassLoader(new URL[] {mainJar.toURL()});
Class<?> appClass = classLoader.find("mainjar.MainApp");
... instantiate the app
}
As you see the main jar must not be loaded from too early, maybe not be on the class path entirely, and hence the use of a separate ClassLoader. The same might probably be done with the main jar on the class path of the starter app, and using Class.forName("mainjar.MainApp"). The Class-Path can be specified in META-INF/MANIFEST.MF.
The secundary jars may reside in a lib/ directory.
For those readers wanting more modular, service oriented, updateable apps, one could make an OSGi application, a container for bundles (=jars), that provide exchangable services and life-time control.
The goal is I want to run a series of htmlSuites. (Must remain html). I've only usually run from command line with the standard jar -jar and that works swell.
Now I wanted to do this in java so I could handle multiple htmlSuites etc. So I've added the server jar to my classpath, and am parsing the arguments to the main class through a String array, but I am getting the following:
HTML suite exception seen:
java.lang.IllegalArgumentException: URI has an authority component
I am using the following code (this is all just for mere testing currently):
String[] arguments = {
"-htmlSuite",
"*firefox",
"https://www.mysite.com",
"\\Projects\\temp\\selenium_stuff\\MyFileUtils\\html\\Feedback\\Feedback-(EM)Suite.html",
"\\Projects\\temp\\selenium_stuff\\MyFileUtils\\results\\Results.html" };
try {
org.openqa.grid.selenium.GridLauncher.main(arguments);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I have been trying multiple things with the locations, but with how I am now parsing it in, it is no longer throwing an exception for not finding the suite file.
Any help is appreciated,