如何使用java运行自定义jar文件副本到classpath命令?

时间:2023-02-05 09:06:56

I have a jar file which I'm using to run as an application. However, every time I run my application I need to add -cp "jar name" to compile it and then run the java application.

我有一个jar文件,我用它作为一个应用程序运行。但是,每次运行我的应用程序时,我都需要添加-cp“jar name”来编译它,然后运行java应用程序。

How can I make a permanent change so that I don't have to use the command line commands for this task? Can I put that in certain lib location?

如何进行永久性更改,以便我不必使用命令行命令执行此任务?我可以把它放在某个lib位置吗?

Note: I don't have to use any IDE. It has to be from a terminal.

注意:我不必使用任何IDE。它必须来自一个终端。

4 个解决方案

#1


1  

If you are on Linux/ Mac, add the following to your ~/.bash_profile

如果您使用的是Linux / Mac,请将以下内容添加到〜/ .bash_profile中

export CLASSPATH=$CLASSPATH:/path/to/jar

If you are on windows, use this..

如果您在Windows上,请使用此..

set CLASSPATH=%CLASSPATH%;\path\to\jar

You can read more about it here and here

你可以在这里和这里阅读更多相关信息

#2


1  

Add your custom JAR in the CLASSPATH. Steps to setup and verify are available here: JAVA PATH & CLASSPATH

在CLASSPATH中添加自定义JAR。这里提供了设置和验证的步骤:JAVA PATH和CLASSPATH

#3


1  

you may copy your lib or additional jars to JAVA_HOME/lib/ext or any directory that is in system variable CLASSPATH

您可以将您的lib或其他jar复制到JAVA_HOME / lib / ext或系统变量CLASSPATH中的任何目录

#4


1  

One more solution: extension libraries, put your jar into $JAVA_HOME/lib/ext

还有一个解决方案:扩展库,将你的jar放入$ JAVA_HOME / lib / ext

One needs to be careful - every java application will pick up this jar

需要注意的是 - 每个java应用程序都会选择这个jar

#1


1  

If you are on Linux/ Mac, add the following to your ~/.bash_profile

如果您使用的是Linux / Mac,请将以下内容添加到〜/ .bash_profile中

export CLASSPATH=$CLASSPATH:/path/to/jar

If you are on windows, use this..

如果您在Windows上,请使用此..

set CLASSPATH=%CLASSPATH%;\path\to\jar

You can read more about it here and here

你可以在这里和这里阅读更多相关信息

#2


1  

Add your custom JAR in the CLASSPATH. Steps to setup and verify are available here: JAVA PATH & CLASSPATH

在CLASSPATH中添加自定义JAR。这里提供了设置和验证的步骤:JAVA PATH和CLASSPATH

#3


1  

you may copy your lib or additional jars to JAVA_HOME/lib/ext or any directory that is in system variable CLASSPATH

您可以将您的lib或其他jar复制到JAVA_HOME / lib / ext或系统变量CLASSPATH中的任何目录

#4


1  

One more solution: extension libraries, put your jar into $JAVA_HOME/lib/ext

还有一个解决方案:扩展库,将你的jar放入$ JAVA_HOME / lib / ext

One needs to be careful - every java application will pick up this jar

需要注意的是 - 每个java应用程序都会选择这个jar