iT邦幫忙

0

netbeans 的檔案maven無法打開

Tzu 2021-06-10 23:37:561324 瀏覽
  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20210610/201190359ng2QFzxts.pnghttps://ithelp.ithome.com.tw/upload/images/20210610/20119035FraXKSkuhI.png

各位大大晚安~

想要詢問如何才可以使有JAVA MAVEN的檔案可以RUN
現在一直出現Cannot run program "cmd" (in directory "C:\Users\User\Documents\NetBeans10Projects\mavenproject1"): Malformed argument has embedded quote: "C:\NetBeans 10.0\incubating-netbeans-10.0-bin\netbeans\java\maven\bin\mvn.cmd" -Dexec.args="-classpath %classpath Sample4" -Dexec.executable="C:\Program Files\Java\jdk-11.0.8\bin\java.exe" -Dexec.classpathScope=runtime -Dmaven.ext.class.path="C:\NetBeans 10.0\incubating-netbeans-10.0-bin\netbeans\java\maven-nblib\netbeans-eventspy.jar" process-classes org.codehaus.mojo:exec-maven-plugin:1.5.0:exec
的錯誤~

還是有沒有參考之料可以推薦的~
我的目的只是要讓下面的程式碼變成一個GUI JAVA IO的檔案而已....


import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Sample4 extends JFrame
{
   private JPanel pn;
   private JLabel lb;
   private JTextArea ta;
   private JScrollPane sp;
   private JButton bt1, bt2;

   public static void main(String[] args)
   {
      Sample4 sm = new Sample4();
   }
  public Sample4()
   {
      // 設定標題
      super("範例-Read/Write File");

      // 建立元件
      lb = new JLabel("請選擇檔案。");
      ta = new JTextArea();
      sp = new JScrollPane(ta);

      pn = new JPanel();
      bt1 = new JButton("讀取");
      bt2 = new JButton("儲存");

      // 新增到容器中
      pn.add(bt1);
      pn.add(bt2);

      add(lb, BorderLayout.NORTH);
      add(sp, BorderLayout.CENTER);
      add(pn, BorderLayout.SOUTH);

      // 登錄傾聽者
      bt1.addActionListener(new SampleActionListener());
      bt2.addActionListener(new SampleActionListener());
      addWindowListener(new SampleWindowListener());

      // 設定框架
      setSize(300, 300);
      setVisible(true);
  }

   // 傾聽者類別
   class SampleActionListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         Container cnt = getContentPane();
         JFileChooser fc = new JFileChooser();
         try{
            if(e.getSource() == bt1){
               int res = fc.showOpenDialog(cnt);
               if(res == JFileChooser.APPROVE_OPTION){       
                  File fl = fc.getSelectedFile();
                  BufferedReader br = new BufferedReader(new FileReader(fl));
                  ta.read(br, null);
                  br.close();
               }
            }
            else if(e.getSource() == bt2){
               int res = fc.showSaveDialog(cnt);
               if(res == JFileChooser.APPROVE_OPTION){       
                  File fl = fc.getSelectedFile();
                  BufferedWriter bw = new BufferedWriter(new FileWriter(fl));
                  ta.write(bw);
                  bw.close();
              }
            }
         }
         catch(Exception ex){
            ex.printStackTrace();
         }
      }
   }
   class SampleWindowListener extends WindowAdapter
   {
      public void windowClosing(WindowEvent e)
      {
         System.exit(0);
      }
   }
}

拜託指點一下~/images/emoticon/emoticon46.gif

https://ithelp.ithome.com.tw/upload/images/20210610/20119035M4lnRWGmon.png

這個是老師的介面

下面就是我的介面看起來完全不同啊
https://ithelp.ithome.com.tw/upload/images/20210610/20119035H1RNkpNI2k.png

還是我要升級成netbean 11?
我已經升級了
https://ithelp.ithome.com.tw/upload/images/20210611/20119035tfnAOD3vEO.png

裝好後現在變成這樣
https://ithelp.ithome.com.tw/upload/images/20210611/20119035WUH1qdlzzk.png

還是不能成功的RUN...qq
https://ithelp.ithome.com.tw/upload/images/20210611/20119035P11aWqDv2z.png

這一頁長得跟老師設定相同還是不行qq

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mavenproject3: Fatal error compiling: invalid target release: 14 -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

連這些很基礎的程式碼也是反紅?
https://ithelp.ithome.com.tw/upload/images/20210611/20119035sUoOz8xZPX.png

發現反紅都是反在看起來都沒有錯的地方啊~
https://ithelp.ithome.com.tw/upload/images/20210611/201190352XHIysOrex.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2021-06-11 11:58:50
最佳解答

你的 project properties 是 mavenproject1``mavenproject1
老師的 project properties 是 ch13

Google錯誤訊息得到以下兩個連結供參考
等別的答案時不妨試試看
netbeans.cnf
也是改 netbeans.cnf

另外
我覺得最根本的解決方法
是在 netbeans new 一個 project
然後把這些原始碼一個一個複製貼上進去
這樣應該馬上就能執行

Tzu iT邦新手 1 級 ‧ 2021-06-11 18:55:11 檢舉

謝謝~可以RUN了 來問下一題 要找How to Open Java File in Design View Netbeans Swings

我要發表回答

立即登入回答