notepad++ compiling and running Java (custom package)

Source: Internet
Author: User



Recently used notepad++ to write a compilation, it feels very handy, so I would like to be able to write Java and compile and run under this excellent editor, because each time you start eclipse is a long time, and eclipse is too much memory ...



So after a variety of Baidu, see the online tutorial, using notepad++ nppexec (notepad++ a plugin) to achieve this.



Attached website: http://jingyan.baidu.com/article/a65957f4fedcc424e67f9bd1.html



Http://jingyan.baidu.com/article/7082dc1c712b77e40a89bd8d.html



These two commands are basically used in the tutorial:


Javac -encoding UTF-8 "$(FULL_CURRENT_PATH)"

Java -cp "$(CURRENT_DIRECTORY)" "$(NAME_PART)"

// Notepad++ environment variables

Variable name

Meaning

Full_current_path

File path name

Current_directory

File directory

file_name

File Full Name

Name_part

File name

Ext_part

File name extension







However, most of the Java code I write uses the package statement, and the "cannot find or fail to load the main class" error when running with these two commands.



Finally there is no way, I have written in C + + two programs.


 
 
1 #include <iostream>
 2 #include <windows.h>
 3 #include <string>
 4 #include <sstream>
 5 #include <fstream>
 6 using namespace std;
 7 
 8 int main(int argc,char* args[])
 9 {
10     
11   string s1(args[1]),s2(args[2]);
12   string j;
13   j="javac  -d  "+s1+" "+s2;     //javac -d  directory_name  file_full_path
14   cout<<j<<endl;
15    system(&j[0]);
16    system("Pause");
17    return 0;
18 }
 
 //myjava.cpp
 1
  //myjava.cpp

 1 #include <iostream>
 2 #include <windows.h>
 3 #include <string>
 4 #include <sstream>
 5 #include <fstream>
 6 using namespace std;
 7 
 8 int main(int argc,char* args[])
 9 {
10     string name(args[2]);
11     cout<<"name:"<<name<<endl;
12     fstream   filestr(args[1],fstream::in|fstream::out);
13     string s="",t="";
14     filestr>>s;
15     filestr>>t;
16     int x=t.length();
17     t[x-1]=‘\0‘;
18     cout<<"package:"<<t<<endl;
19     filestr.close();
20     string j;
21     stringstream ss1;
22     ss1<<"java "<<t<<"."<<name;       //java  package_name.class_name
23     j=ss1.str();
24     cout<<j<<endl;
25     system(&j[0]);
26     system("Pause");
27     return 0;
28 }





Put the generated two EXE files in a folder (such as F:\\myshell), and then add this folder to the system's PATH environment variable,



Then open notepad++, click Run in the Run menu



Enter the filename of the EXE, and the two parameters after Myjavac are "$ (current_directory)" "$ (Full_current_path)"



The two arguments after Myjava are "$ (full_current_path)" "$ (Name_part)" (separated by a space between the arguments)



Then click Save, enter a name, select the shortcut (not optional), you can add your own commands to the Run menu.









You can also combine two commands into a single command by modifying the C + + code or by using a batch process.






notepad++ compiling and running Java (custom package)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.