Java使用notepad ++和nppexec进行编译和运行 [英] Java compile and run using notepad++ and nppexec

查看:286
本文介绍了Java使用notepad ++和nppexec进行编译和运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请记住,在Windows Shell中进行编译是可行的,因此,此问题成为PATH问题的可能性很小(如果不是零的话).

Please keep in mind that compiling in the windows shell works, so there is little (if not zero) possibility of this issue being a PATH issue.

我花了很多时间研究如何做到这一点,我在网上发现的所有结果都表明您可以做到:

I have spent a lot of time research how to do this, and all the results I found online say that you can do:

NPP_SAVE
javac $(FILE_NAME)
java $(NAME_PART)

但这对我不起作用.在NPP_EXEC控制台中,我可以键入java,并且可以从cmd中获得正常的结果,但是任何时候键入javac时,都会得到可怕的错误代码2错误:

but that does not work for me. In the NPP_EXEC console, I can type java, and I get the normal results as I would from cmd, but any time I type javac, I get the dreaded error code 2 error:

================ READY ================
javac
javac
CreateProcess() failed with error code 2:
The system cannot find the file specified.

================ READY ================

编辑

我必须澄清一些困惑:

Edit

I must clarify some confusion:

  1. 此解决方案应在单个脚本中运行.目标是能够更改代码,按热键组合(在Visual Studio中为F5),它可以生成/编译并运行.
  2. 实际问题iirc是notepad ++由于某种原因无法识别javac.

很抱歉给您带来混乱...

Sorry for the confusion...

推荐答案

在经过5个多小时的谷歌搜索和反复试验后,我终于有了一个有效的NPP Exec脚本,该脚本可以在不离开notepad ++的情况下编译和运行Java程序.

I finally, after 5+ hours of googling and trial and error, have a working NPP Exec script that will compile and run a java program without leaving notepad++.

NPP_SAVE
cmd /K (javac "$(FULL_CURRENT_PATH)" && exit) || exit
cmd /K (cd /D "$(CURRENT_DIRECTORY)" && java $(NAME_PART) && exit) || exit

剩下的唯一事情就是找到一种方法来执行上述操作,而不必调用并将参数发送到cmd,所有这些操作都在notepad ++和nppexec中进行.

The only thing left would be finding a way to do the above, without having to call and send parameters to cmd, all in notepad++ and nppexec.

如下面的注释中所述,如果您使用的是包,则需要相应地编辑第二行.如果您的软件包名称与文件名相同,则应该可以使用以下内容:

As noted in the comment below, if you're using a package, you will need to edit the second line accordingly. If your package name is the same as your file name, the below should work:

cmd/K(cd/D"$(CURRENT_DIRECTORY)"&& java -cp .. $(NAME_PART).$(NAME_PART)&&退出)||退出

cmd /K (cd /D "$(CURRENT_DIRECTORY)" && java -cp .. $(NAME_PART).$(NAME_PART) && exit) || exit

这篇关于Java使用notepad ++和nppexec进行编译和运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆