Code works fine, then after maven install, there are errors in both the jar and the IDE
Exception in Application start method:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
java eclipse maven fxml
add a comment |
Exception in Application start method:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
java eclipse maven fxml
check thatEmployeeView.fxml
is included in yourjar
– Scary Wombat
Nov 21 at 1:41
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48
add a comment |
Exception in Application start method:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
java eclipse maven fxml
Exception in Application start method:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at edu.citytech.view.EmployeeMain.start(EmployeeMain.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more
Exception running application edu.citytech.view.EmployeeMain
Here's the class with the main method, EmployeeMain.java:
package edu.citytech.view;
import edu.citytech.utitlity.GlobalVariables;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class EmployeeMain extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EmployeeView.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
// * new *
primaryStage.setResizable(false);
primaryStage.setTitle("Employee List");
primaryStage.getIcons().add(new Image(EmployeeMain.class.getResourceAsStream("People.jpg")));
}
public static void main(String args) {
if (args.length > 0) {
GlobalVariables.portNumber = (Integer.parseInt(args[0]));
}
launch(args);
}
}
And what fixes this is adding a space to any of the files and saving it, then restarting the Eclipse IDE, and running it again from the IDE. What breaks it is when I run mvn clean and mvn install, and then running the jar file it created. Everyone in my class is having this problem, and the teacher has no idea how to fix it. It just works for some people and it doesn't for others. However this time, this isn't working no matter what I try. Only works in the IDE until I use maven to create a jar. Then it won't work until I modify and save a file, and then restart the IDE. Everything is named properly and it just works and doesn't work randomly. Is this an IDE problem or a project problem?
What can I do so that I can make a jar file that works when it's run?
java eclipse maven fxml
java eclipse maven fxml
asked Nov 21 at 1:40
User9123
32
32
check thatEmployeeView.fxml
is included in yourjar
– Scary Wombat
Nov 21 at 1:41
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48
add a comment |
check thatEmployeeView.fxml
is included in yourjar
– Scary Wombat
Nov 21 at 1:41
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48
check that
EmployeeView.fxml
is included in your jar
– Scary Wombat
Nov 21 at 1:41
check that
EmployeeView.fxml
is included in your jar
– Scary Wombat
Nov 21 at 1:41
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48
add a comment |
2 Answers
2
active
oldest
votes
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
add a comment |
3 issues possible
- it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
- include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
- That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404149%2fcode-works-fine-then-after-maven-install-there-are-errors-in-both-the-jar-and%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
add a comment |
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
add a comment |
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
I figured out how to get it to work. Really annoying but really simple. I'm going to write it here for anyone who is probably finding this page through a search engine.
Right click on project folder > Maven > Update Project...
Update selected project
Right click the project folder and run in local terminal
mvn install
And DO NOT DO MVN CLEAN
answered Nov 21 at 4:25
User9123
32
32
add a comment |
add a comment |
3 issues possible
- it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
- include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
- That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
add a comment |
3 issues possible
- it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
- include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
- That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
add a comment |
3 issues possible
- it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
- include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
- That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
3 issues possible
- it sounds like you need the IDE to recompile the code for it to work again in eclipse too? not sure why that would be actually unless its the java version used ...
eclipse usually rebuilds given any change (e.g. your space added to file)
is your eclipse IDE and maven compile are using the same java version?
delete your ./target directory and
add this to maven pom.xml to make sure you're using the right java version (e.g. for java 1.8):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
- include the file in the jar build
Also the copy your EmployeeView.fxml should be in src/main/resources and the file wont be making it into your jar file unless you include:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
- That code won't work within the jar file at runtime see these answers:
How to reference a resource file correctly for JAR and Debugging?
and update your code to use getREsourceAsStream e.g. here's a method i use:
public void load(String resource, HashSet<String> hashset) {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is_awl = classloader.getResourceAsStream(resource);
BufferedReader reader = new BufferedReader(new InputStreamReader(is_awl));
String line;
try {
while ((line = reader.readLine()) != null) {
hashset.add(line.trim());
}
} catch (IOException e) {
System.err.println("LexicalFeatures can't initialise:"
+ resource + " hashset: "+ e.getMessage());
e.printStackTrace();
}
}
edited Nov 21 at 3:18
answered Nov 21 at 2:46
BWats
92
92
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404149%2fcode-works-fine-then-after-maven-install-there-are-errors-in-both-the-jar-and%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
check that
EmployeeView.fxml
is included in yourjar
– Scary Wombat
Nov 21 at 1:41
That hits really close. It's actually not in the jar. Not unless I copy it to the src/main/resources. However it still won't work, I think it has to be in the same package as where the main method is.
– User9123
Nov 21 at 1:48