英文:
how to call javaBridge Main from java application
问题
我有关于这个问题的疑问
这是我的主类
这是我的代码
导入dxtr.mtapi.mt4.data.QuoteClient;
导入php.java.bridge.JavaBridge;
public class Main {
public static void main(String[] args) throws IOException {
QuoteClient qc = new QuoteClient(12342, "xasd", "localhost", 9900);
JavaBridge.main(args);
}
}
运行时出现错误
线程 "main" 中的异常 "java.lang.NoClassDefFoundError: php/java/bridge/JavaBridge"
at dxtr.main.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: php.java.bridge.JavaBridge
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
JavaBridge 是不同的 jar 包。所以我从本地添加了它,就像下面这个 pom 里面的一样。为什么我的代码在这里报错?
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<!-- 构建可执行的 JAR -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Build-Jdk>${jdk.version}</Build-Jdk>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Specification-Title>${project.name} Library</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Class-Path>libs/JavaBridge-1.0.0.jar</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>dxtr.mtapi.mt4.main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我尝试使用这个示例中的 pom,来更新我的 pom。但我仍然不能在我的代码中运行 JavaBridge。如何从我的代码中运行 java bridge.jar?
这是我添加到代码中的图片
[![这是 JavaBridge 截图][1]][1]
那么如何解决这个问题?我是否需要添加代码或者其他什么?
[1]: [![进入图片描述][1]]
[1]: https://i.stack.imgur.com/dhgTO.png
我还尝试过这个命令
java -cp JavaBridge.jar:build Dxtr.main.Main
但是我得到了错误:
错误: 找不到或无法加载主类 Dxtr.main.Main
那么在尝试运行 JavaBridge.main 时如何解决这个问题?
英文:
i have question about this
this is my main class
this is mycode
import dxtr.mtapi.mt4.data.QuoteClient;
import php.java.bridge.JavaBridge;
public class Main {
public static void main(String[] args) throws IOException {
QuoteClient qc = new QuoteClient(12342, "xasd", "localhost", 9900);
JavaBridge.main(args);
}
}
error when i run
Exception in thread "main" java.lang.NoClassDefFoundError: php/java/bridge/JavaBridge
at dxtr.main.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: php.java.bridge.JavaBridge
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
the JavaBridge are different jar. so i add from local like this one here my pom. why my code error at there ?
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Build-Jdk>${jdk.version}</Build-Jdk>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Specification-Title>${project.name} Library</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Class-Path>libs/JavaBridge-1.0.0.jar</Class-Path>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>dxtr.mtapi.mt4.main.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
i have try using from this here my pom from example from here https://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path
i have update my pom like that. but i still cannot run javaBridge in my code. how to run java bridge.jar from my code ?
here the picture when i have add to my code
so how to fix the problem ? it is i must add the code or something like what ?
1: [
i also have try using this
java -cp JavaBridge.jar:build Dxtr.main.Main
but i got error like :
Error: Could not find or load main class Dxtr.main.Main
so how to fix this problem when try to run JavaBridge.main
专注分享java语言的经验与见解,让所有开发者获益!
评论