java "launch" returns "java.lang.ClassNotFoundException" - java

when i try to run my java file with javafx from command prompt im returned with a error, the error says the problem of the code is coming from a java launch command which i dont know how to fix. Please give a fix.
the error:
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Main1
at javafx.graphics#19/javafx.application.Application.launch(Application.java:314)
at Main1.main(Main1.java:47)
Caused by: java.lang.ClassNotFoundException: Main1
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:488)
at java.base/java.lang.Class.forName(Class.java:467)
at javafx.graphics#19/javafx.application.Application.launch(Application.java:302)
at Main1.main(Main1.java:47)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:421)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
code:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.web.*;
import javafx.scene.image.*;
public class Main1 extends Application {
public void start(Stage stage)
{
try {
stage.setTitle("Fierce Pcs");
WebView w = new WebView();
WebEngine e = w.getEngine();
e.load("https://www.example.com/");
stage.getIcons().add(new Image(getClass().getResourceAsStream("icon.png")));
Scene scene = new Scene(w, w.getPrefWidth(),
w.getPrefHeight());
stage.setScene(scene);
stage.show();
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void main(String args[])
{
launch(args);
}
}
the command which i give the command prompt:
java --module-path %PATH_TO_FX% --add-modules javafx.fxml,javafx.web C:\Users\example\OneDrive\Desktop\Main1.java

Try this:
launch(Main1.class, args);
Or stay with launch(args) and compile your Main1.java to Main1.class and run (i suppose this is the default (none) package):
javac --module-path %PATH_TO_FX% --add-modules javafx.fxml,javafx.web Main1.java
java --module-path %PATH_TO_FX% --add-modules javafx.fxml,javafx.web Main1

Related

Executing a new JavaFX application on a separate JVM

I'm trying to launch a new process on a separate JVM via code following the method illustrated here:
Executing a Java application in a separate process
The code I'm using is the following (taken from the question above):
public static int exec(Class klass) throws IOException, InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getName();
ProcessBuilder builder = new ProcessBuilder(javaBin,"-cp",classpath,className);
Process process = builder.inheritIO().start();
process.waitFor();
return process.exitValue();
}
...in which klass is the class I want to launch.
This would work for a normal Java process, but the problem is that I'm trying to launch a JavaFX application, and the code above generates the following error:
Error: JavaFX runtime components are missing, and are required to run this application
So, to add the JavaFX modules, I tried including the --module-path and --add-modules commands in the declaration of builder, I even attempted copying and pasting the entire execution command, and I kept getting this other error:
Unrecognized option: (command string with modules)
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
How could I solve this?
Let me know if details are needed.
Since the advent of modules, there are at least three different ways a JavaFX application can be configured:
Put everything on the module-path, including the JavaFX modules and your module.
This is the ideal situation but not always possible/viable (e.g. because of incompatible dependencies).
Put the JavaFX modules on the module-path and your own code on the class-path.
This configuration requires the use of --add-modules.
Put everything on the class-path, including the JavaFX modules and your own code.
With this configuration your main class cannot be a subtype of Application. Otherwise you get the error you mentioned in your question: "Error: JavaFX runtime components are missing, and are required to run this application".
This configuration allows for easy use of so-called fat/uber JARs.
Warning: This approach is explicitly unsupported.
The command line used with ProcessBuilder will depend on which configuration your application uses. You also have to take into account any other options passed the command line, such as the default encoding or locale. Unfortunately, your question doesn't provide enough information to tell what exactly is going wrong. The error you mention makes me think you're using the third configuration, but I can't be sure.
That said, I'll give some examples of launching the same application from within the application; you should be able to modify things to fit your needs. Note I used Java/JavaFX 13.0.1 when testing the below code.
Configuration #1
Put everything on the module-path.
module-info.java:
module app {
requires javafx.controls;
exports com.example.app to
javafx.graphics;
}
Main.java:
package com.example.app;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import static java.lang.System.getProperty;
public class Main extends Application {
private static void launchProcess() {
try {
new ProcessBuilder(
Path.of(getProperty("java.home"), "bin", "java").toString(),
"--module-path",
getProperty("jdk.module.path"),
"--module",
getProperty("jdk.module.main") + "/" + getProperty("jdk.module.main.class"))
.inheritIO()
.start();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
#Override
public void start(Stage primaryStage) {
Button launchBtn = new Button("Launch process");
launchBtn.setOnAction(
event -> {
event.consume();
launchProcess();
});
primaryStage.setScene(new Scene(new StackPane(launchBtn), 500, 300));
primaryStage.setTitle("Multi-Process Example");
primaryStage.show();
}
}
Command line:
java --module-path <PATH> --module app/com.example.app.Main
Replace "<PATH>" with a path containing both the JavaFX modules and the above module.
Configuration #2
Put JavaFX modules on the module-path and your code on the class-path.
Main.java:
package com.example.app;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import static java.lang.System.getProperty;
public class Main extends Application {
private static void launchProcess() {
try {
new ProcessBuilder(
Path.of(getProperty("java.home"), "bin", "java").toString(),
"--module-path",
getProperty("jdk.module.path"),
"--add-modules",
"javafx.controls",
"--class-path",
getProperty("java.class.path"),
Main.class.getName())
.inheritIO()
.start();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
#Override
public void start(Stage primaryStage) {
Button launchBtn = new Button("Launch process");
launchBtn.setOnAction(
event -> {
event.consume();
launchProcess();
});
primaryStage.setScene(new Scene(new StackPane(launchBtn), 500, 300));
primaryStage.setTitle("Multi-Process Example");
primaryStage.show();
}
}
Command line:
java --module-path <M_PATH> --add-modules javafx.controls --class-path <C_PATH> com.example.app.Main
Replace "<M_PATH>" with a path containing the JavaFX modules and replace "<C_PATH>" with a path containing the above code.
Configuration #3
Put everything on the class-path. Note the main class (now Launcher) is not a subclass of Application.
Launcher.java:
package com.example.app;
import javafx.application.Application;
public class Launcher {
public static void main(String[] args) {
Application.launch(Main.class, args);
}
}
Main.java:
package com.example.app;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import static java.lang.System.getProperty;
public class Main extends Application {
private static void launchProcess() {
try {
new ProcessBuilder(
Path.of(getProperty("java.home"), "bin", "java").toString(),
"--class-path",
getProperty("java.class.path"),
Launcher.class.getName())
.inheritIO()
.start();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
#Override
public void start(Stage primaryStage) {
Button launchBtn = new Button("Launch process");
launchBtn.setOnAction(
event -> {
event.consume();
launchProcess();
});
primaryStage.setScene(new Scene(new StackPane(launchBtn), 500, 300));
primaryStage.setTitle("Multi-Process Example");
primaryStage.show();
}
}
Command line:
java --class-path <PATH> com.example.app.Launcher
Replace "<PATH>" with a path containing the JavaFX JARs and the above code.

JavaFX Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>

I just wrote this code here:
package SpellcheckerClient;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = FXMLLoader.load(getClass().getResource("/controller/gui.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Spellchecker Client");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
And this is the corresponding controller.
package controller;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import spellchecker.remote.SpellcheckerRemoteAdapter;
public class Controller {
#FXML
TextField input;
#FXML
Button send;
#FXML
TextArea area;
#FXML
Button connect;
private SpellcheckerRemoteAdapter adapter;
#FXML
private void send() throws RemoteException{
String toCheck = input.getText();
this.area.appendText(toCheck + "\n");
this.area.appendText(checkRoutine(toCheck, this.adapter) + "\n\n");
this.input.clear();
}
public void initiateConnection() {
try {
Registry registry = LocateRegistry.getRegistry(1088);
this.adapter = (SpellcheckerRemoteAdapter) registry.lookup(SpellcheckerRemoteAdapter.NAME);
this.area.appendText("Verbindung erfolgreich aufgebaut!\n");
connect.setDisable(true);
} catch (Exception e) {
if(this.adapter == null) {
this.area.appendText("Server nicht gefunden!\n");
}
}
}
private static String checkRoutine(String input, SpellcheckerRemoteAdapter adapter) throws RemoteException {
if (input == null || input.isEmpty()) {
return "Bitte etwas eingeben!";
}
String[] words = input.split(" ");
boolean control = true;
String output = "";
for(String word : words) {
if(!adapter.check(word)) {
control = false;
output += word + ":\t" + adapter.getProposal(word) + "\n";
}
}
if(control) {
return "Alles Okay!\n";
}
return output;
}
}
If I run this code on my Laptop, where I wrote it, it runs perfectly fine in Eclipse and as runnable Jar. However, if I try to run the JAR on another computer i receive this error message:
Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.graphics/com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
On my Laptop and my Computer are the same Versions of the JDK/JRE installed.
I don't really get what the error message is telling me.
Hello I have the same issue on my Eclipse environnement (Windows 10 OS),
adding in VM option -Djava.library.path="C:\WINDOWS\Sun\Java\bin" solved my problem
That means that javafx-graphics-[version]-win.jar call some native dll. And You have to found were those dll is stored.
I found the path, thanks to jvisualvm and showing the VM option for the case where it's the application run correctly.
Hoping that it will solve your problem.
Which JDk you have installed?? I have the same issue and i use JDK 8 instead of JDK 9. Which helped me.Sample Image of Exception
This is because jar which i created it was created on JDK 8 through a different system.
Where as when it was executing on another system which has JDK9. So it is version incompatible.
After keeping single JDK 8 and mapped it to system environment when i try to run my jar it worked for me.
Good Luck :)

Unable to run the javafx project using command line

I recently had created the javafx project in eclipse, I successfully ran in eclipse and it just works fine.
I wanted to run my project using the command line interface.
I am able to compile successfully but not able to run and it keeps on giving "Error: could not find or load main class Main"
Compile command (Works fine):
javac -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" Main.java
Main.class is created after the above command.
Run Command (doesn't work):
java -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar;." Main
I would like to know what am I missing here in order to successfully run it.
Adding Main.java
package application;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
private Stage primaryStage;
private BorderPane root;
#Override
public void start(Stage primaryStage) {
try {
this.primaryStage = primaryStage;
primaryStage.setTitle("Mojo");
initRootLayout();
showMapLayout();
} catch(Exception e) {
e.printStackTrace();
}
}
private void showMapLayout() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/application/viewControllers/mapView.fxml"));
AnchorPane mapPane = (AnchorPane)loader.load();
root.setCenter(mapPane);
} catch (IOException e) {
e.printStackTrace();
}
}
private void initRootLayout() {
try{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/application/viewControllers/RootLayout.fxml"));
root = (BorderPane)loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public static void main(String[] args) {
launch(args);
}
}
Your class is declared to be in the package application. So, to compile it so that you get the correct folder structure you should compile with the -d option:
javac -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar" -d . Main.java
That should create a directory called application, and Main.class will be in there.
Then execute (from the same folder, not from the application folder) with
java -cp "C:\Program Files (x86)\Oracle\JavaFX 2.2 Runtime\lib\jfxrt.jar";. application.Main

Accessing java fx clipboard from a commandline application?

This might be a stupid question from a newbie, so bear with me. Here is what I did:
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javax.sound.sampled.Clip;
public class Main {
public static void main(String[] args) {
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
content.putHtml("<b>Some bold html</b>");
clipboard.setContent(content);
}
}
I got the following error:
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/kaiyin/IdeaProjects/untitled8/out/production/untitled8:/Applications/IntelliJ IDEA 13 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.company.Main
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.xrender=true
Exception in thread "main" java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = main
at com.sun.glass.ui.Application.checkEventThread(Application.java:432)
at com.sun.glass.ui.ClipboardAssistance.<init>(ClipboardAssistance.java:40)
at com.sun.javafx.tk.quantum.QuantumToolkit.getSystemClipboard(QuantumToolkit.java:1127)
at javafx.scene.input.Clipboard.getSystemClipboardImpl(Clipboard.java:410)
at javafx.scene.input.Clipboard.getSystemClipboard(Clipboard.java:175)
at com.company.Main.main(Main.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 1
Is it possible to access javafx cliboard without creating a gui at all?
I'll ignore the question of why you would ever want to do this...
As pointed out in the comments, you need to start the FX Application Thread in order to access the JavaFX clipboard. However, you don't actually need to show a Stage at any point.
The following compiles and runs:
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.stage.Stage;
public class ClipboardTest extends Application {
#Override
public void start(Stage primaryStage) {
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
content.putHtml("<b>Some bold html</b>");
clipboard.setContent(content);
Platform.exit();
}
public static void main(String[] args) {
launch(args);
}
}

Runnig spring via Daemon as Standalone

I am trying to run Spring via Daemon service as stand alone application ofcourse.
I have configured run.sh script and added to it all Spring jars framework.
Now i am trying to execute my starting point class from the Daemon classes this way:
Code:
public class FeedDaemon implements Daemon
{
public FeedDaemon()
{
}
protected final static Logger log = LoggerFactory.getLogger(FeedDaemon.class);
protected boolean shouldBeRunning = false;
protected ProviderFactory runner = null;
#Override
public void destroy()
{
runner = null;
}
#Override
public void init(DaemonContext arg0) throws Exception
{
runner = new ProviderFactory();
}
public void start() throws RuntimeError, ConfigError
{
log.info("Starting daemon");
runner.start();
}
public void stop() throws Exception
{
log.info("Starting Shutting daemon ...");
runner.stop();
}
}
Code:
package com.spring.test;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.spring.aspect.Spring3HelloWorld;
import com.spring.beans.ParkingCar.CarBean;
import com.spring.beans.ParkingCar.CarMaker;
import com.spring.beans.ParkingCar.FourWheelsVechile;
import com.spring.beans.ParkingCar.TwoWheelsVechile;
import com.spring.beans.ParkingCar.Vechile;
import com.spring.beans.ParkingCar.VechileDetails;
import com.spring.beans.calculator.CalculateNumbersHolderBean;
import com.spring.beans.calculator.CalculateStrategyBean;
import com.spring.beans.calculator.CalculatorBean;
public class Spring3HelloWorldTest
{
static Logger logger = Logger.getLogger(Spring3HelloWorldTest.class);
public static void execute()
{
try
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
logger.debug("3");
Vechile fourWheelsVechile = (FourWheelsVechile) context.getBean("Ambulance");
fourWheelsVechile.drive();
CarMaker carMaker = (CarMaker) context.getBean("carMaker");
CarBean carBean = carMaker.createNewCar();
carBean.driveCar();
}
catch (Throwable e)
{
logger.error(e);
}
}
}
And I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.daemon.support.DaemonLoader.load(DaemonLoader.java:164)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at com.spring.runner.FeedDaemon.init(FeedDaemon.java:37)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 6 more
Cannot load daemon
Service exit with a return value of 3
thats my run.sh script:
export JAVA_HOME=/../
FIXGW=/../FIXGW
CLASSPATH=$FIXGW/lib/FeedHandler.jar:$FIXGW/lib/FixSpring.jar:$FIXGW/lib/org.springframework.web-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.struts-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.servlet-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.web.portlet-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.test-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.orm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.jms-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.jdbc-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.context.support-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.aspects-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.transaction-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.oxm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.instrument-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.instrument.tomcat-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.expression-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.core-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.context-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.beans-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.asm-sources-3.1.1.RELEASE.jar:$FIXGW/lib/org.springframework.aop-sources-3.1.1.RELEASE.jar:$FIXGW/lib/commons-daemon-1.0.3.jar
cd $FIXGW
/../jsvc -user fox \
-XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:SurvivorRatio=16 \
-Dlog4j.configuration=file:$FIXGW/conf/log4j.properties \
-outfile /dev/null \
-errfile $FIXGW/logs/error.log \
-verbose -classpath $CLASSPATH \
com.spring.runner.FeedDaemon
Any idea?
thanks,
ray.
You seem to have added all the jars containing the Spring java source (uncompiled code). You should instead add the jars not named ...-sources... to the class path.
spring jars are not in classpath. Check this my answer. Add all libraries in classpath via command line(ofcourse in your shell script).
Well I see your problem now. You have source files in classpath. Those are mentioned as org.springframework.web.servlet-sources-3.1.1.RELEASE.jar while compiled jars are mentioned as org.springframework.web.servlet-3.1.1.RELEASE.jar

Categories

Resources